using-directives Questions

41

Solved

I have heard using namespace std; is wrong, and that I should use std::cout and std::cin directly instead. Why is this? Does it risk declaring variables that share the same name as something in the...
Wadley asked 21/9, 2009 at 3:8

2

Solved

C#10 in .NET 6.0 supports a new feature called global using directive. It seems to do 2 things: When you have a namespace in the global using, you don't have to include the using ... for that name...
Merissameristem asked 19/1, 2023 at 10:24

2

Solved

I have a function in my code which only accepts a class member method as a template parameter. I need to call this method using a class method which is inherited from a parent class. Here is an exa...
Javed asked 4/5, 2022 at 11:10

7

Solved

I'm pretty sure I know the answer but I'm wondering if there's a way to define a global "using" directive in my C# projects so that I don't have to repeat the directive on top of every code file. ...

1

Solved

Is there a consensus within the C# development community on the .cs filename in which global using statements are declared? I was going to adopt the filename GlobalUsings.cs but then found that a h...
Dowzall asked 9/12, 2021 at 19:2

1

All students are surprised by the behavior of C++ using-directives. Consider this snippet (Godbolt): namespace NA { int foo(Zoo::Lion); } namespace NB { int foo(Zoo::Lion); namespace NC { names...
Fowling asked 19/12, 2020 at 0:53

7

Solved

I like to put my using directives inside the current namespace, and not outside as VS and Resharper per default puts them. Does anyone know of a macro/standard functionality that sorts/removes unu...
Schadenfreude asked 4/5, 2009 at 16:25

3

Solved

For my project I am using some pretty convoluted data structures, e.g. std::unordered_map<int, std::list<std::shared_ptr<const Foo>>> for which I would like to declare type ali...
Anaximander asked 2/9, 2019 at 12:23

1

Solved

What is the meaning of the highlighted sentence below? Does it have anything to do with function templates? [over.load]/1: Not all function declarations can be overloaded. Those that cannot be...
Celebrant asked 15/7, 2019 at 14:44

2

Solved

I came across the following situation in one of my projects, where a base class has a function template, which is hidden by a non-templated function in a derived class template. Further down the cl...
Harned asked 22/5, 2019 at 7:47

1

Solved

I can create the following: using Foo = struct { /*Implementation*/ }; template<class> using Bar = Foo; However the following is not allowed: template<class> using Bar = struct { /...
Nonstop asked 27/4, 2019 at 7:14

2

Solved

Consider this library header: #include<vector> #include<algorithm> #include<iostream> namespace Lib { namespace detail { using namespace std; template<class T> void s...
Bona asked 12/9, 2017 at 4:56

2

How do you pass an alias type defined by using to the generic class? I tried the following code: using ID = Int32; // it might be replaced with `String`. using CC = C<ID>; public cla...
Enter asked 28/7, 2017 at 6:26

5

Solved

I get the following error when I try to compile my C# program: The type or namespace name 'Login' could not be found (are you missing a using directive or an assembly reference?) using System; u...
Sharpwitted asked 27/4, 2010 at 13:1

1

In my C++ JSON library, I recently had a regression with GCC7. I stripped down the affected code and hope to understand the error. The code Consider this header myclass.hpp: #pragma once templa...
Gladiatorial asked 5/6, 2017 at 11:23

1

Solved

I'm writing a system to process snippets written as unit tests for Noda Time, so I can include the snippets in the documentation. I've got a first pass working, but I wanted to tidy up the code. On...
Maximilien asked 18/5, 2017 at 21:44

1

When using the line using std::literals::chrono_literals::operator""s; in g++ 6.3.0, the compiler issues a warning stating: warning: literal operator suffixes not preceded by '_' are reserved...

3

Solved

3

Solved

The following C++ test code does not link (gcc 4.9.2, binutils 2.25). The error is In function 'main': undefined reference to 'X::test'. 01: #include <string> 02: #include <iostream> 0...
Misericord asked 7/12, 2015 at 8:21

3

Solved

I know that I the scope of the using directive is limited to a block or a function when put inside. Then it will apply only to that scope. But if the block is a namespace it apparantly applie...
Soloman asked 6/10, 2015 at 8:55

2

Solved

Is the following program well-formed or ill-formed according to the c++ standard? namespace N { int i; } using namespace N; using ::i; int main() {} I get different results with different compil...

3

Solved

Please consider the following code: struct A { void f() { } }; struct B1 : A { }; struct B2 : A { }; struct C : B1, B2 { void f() // works { B1::f(); } //using B1::f; // does not work ...

2

Is there a possibility to have a using directive whose scope is limited to a single class? Note, that what I want to "use" is not contained in the parent of the current class. For simplicity, ass...
Sobersided asked 5/12, 2014 at 9:45

16

Solved

I have a C# solution with several projects in Visual Studio 2010. One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). Th...

1

Solved

Sometimes I find code like the following (actually some class-wizards create such code): // C.h namespace NS { class C { void f(); }; } and in the implementation file: // C.cpp #include "C.h...
Redemption asked 7/8, 2014 at 7:50

© 2022 - 2024 — McMap. All rights reserved.