Questions tagged [using-declaration]

Use this tag for questions related to the 'using' keyword in C++.

164 questions
7
votes
2 answers

Private using declaration of base constructor is not private

The using declaration for the base constructor is private, but the class can still be constructed. Why? Accessibility works differently for the operator[]'s using declaration which must be public. #include template class Vec :…
wally
  • 10,717
  • 5
  • 39
  • 72
7
votes
3 answers

Is a using-declaration supposed to hide an inherited virtual function?

struct level0 { virtual void foo() = 0; }; struct level1 : level0 { virtual void foo() { cout <<" level1 " << endl; } }; struct level2 : level1 { virtual void foo() { cout <<" level2 " << endl; } }; struct level3 : level2 { using…
balki
  • 26,394
  • 30
  • 105
  • 151
7
votes
0 answers

IntelliSense: redeclaration of alias template

IntelliSense in the Visual Studio 2017 (15.1) underlines the word Type in the following code: #include template struct Test : std::true_type { }; template using Type /*!*/ =…
Evg
  • 25,259
  • 5
  • 41
  • 83
7
votes
2 answers

The difference between declaring a name, introducing a name, and declaring an entity

From the C++11 standard, §7.3.3[namespace.udecl]/1: A using-declaration introduces a name into the declarative region in which the using-declaration appears. using-declaration: using typenameopt nested-name-specifier unqualified-id ; using ::…
Supremum
  • 542
  • 7
  • 23
7
votes
2 answers

'using' declaration as SFINAE

Could I use SFINAE (or another technique) for using declaration while private deriving from template class? For better understanding see code below: #include struct S1 { void f() { std::cout << "S1::f\n"; } }; struct S2 { void…
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
7
votes
2 answers

Should a class-member using-declaration with a dependent qualified-id be a dependent name?

Draft N3337 of the C++11 standard states in [namespace.udecl] A using-declaration introduces a name into the declarative region in which the using-declaration appears. Every using-declaration is a declaration and a member-declaration and so can be…
willj
  • 2,991
  • 12
  • 24
7
votes
1 answer

Downsides to the 'Using' keyword in C++ as applied to derived classes

I recently discovered a new application of the using keyword; not with reference to the namespace functionality but inside a derived class declaration. In my case this was pertinent in regards the issues surrounding the 'operator='…
user3259248
6
votes
8 answers

Is it worth removing "using System" from my files?

Developing a series of POCOs on my project, and just realized that some of them doesn't need the using System; clause. Is there any performance or size penalty for leaving unused using ; on my objects or project ? Will my classes get bigger,…
Machado
  • 741
  • 2
  • 6
  • 19
6
votes
2 answers

A way to use all the unqualified names in a C++0x enum class?

The new C++ (C++0x or C++11) has an new kind of enum, an "enum class" where the names are scoped to the enum (among other things). enum class E { VAL1, VAL2 }; void fun() { E e = E::VAL1; // Qualified name } I'm wondering, however, if I…
Rob N
  • 15,024
  • 17
  • 92
  • 165
6
votes
0 answers

Using constrained template base member function in derived class, which one should be hidden?

Let's consider the code bellow where base members are declared in the derived class. GCC and Clang do not agree on which member is going to be hidden: template concept C = true; struct base { template void foo0…
Oliv
  • 17,610
  • 1
  • 29
  • 72
6
votes
1 answer

Using declaration as overrider

We have the following simple (and slightly modified to add main and output) example in the Standard: struct A { virtual void f() { cout << "A\n"; } }; struct B : virtual A { virtual void f() { cout << "B\n"; …
6
votes
2 answers

C++ using statement in member function scope

If I want to use a member of a template base class from a template derived class, I have to bring it into scope as such: template struct base { void foo(); }; template struct derived : base { using…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
6
votes
1 answer

using method from indirect parent

Consider following code: class user_error : public std::runtime_error { public: using std::exception::what; explicit user_error(const std::string& what_arg):std::runtime_error(what_arg){} }; class with_overriden_what : public user_error…
6
votes
1 answer

Overload resolution between template members in base and derived classes

Microsoft compiler (Visual Studio 2017 15.2) rejects the following code: #include struct B { template = 0> void f() { } }; struct D : B { using B::f; template
Evg
  • 25,259
  • 5
  • 41
  • 83
6
votes
2 answers

Name lookup in using-declaration via using-directive

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 compilers: Clang…
1 2
3
10 11