Questions tagged [using-declaration]

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

164 questions
4
votes
1 answer

Specifying an in-class using-declaration targeting different functions with the same name

When using a using-declaration to expose base class' methods, how can I go about exposing methods with the same name but different parameters? class Base { protected: void f(); void f(int); }; class Derived: public Base { using Base::f;…
invertedPanda
  • 142
  • 1
  • 7
4
votes
1 answer

C++ visibility of inherited constructor

When I use using like this why is the constructor inherited publicly? class Base { int x; public: Base(int x); }; class Derived : public Base { using Base::Base; }; I can now do: Derived d (2); I thought that using declarations had the…
user7475082
4
votes
2 answers

Overloading std::begin() and std::end() for non-arrays

Let's assume I have the following Data class: struct Data { char foo[8]; char bar; }; and the following function, my_algorithm, which takes a pair of char * (similar to an STL algorithm): void my_algorithm(char *first, char *last); For…
JFMR
  • 23,265
  • 4
  • 52
  • 76
4
votes
1 answer

Cannot use "using" declaration for std::tuple on Apple LLVM 7.3.0

I'm attempting to use tuple in my program, and for some reason I am not able to simplify the call with a using declaration. For example: #include using std::tuple; ... This throws an error when attempting to compile it: error: no member…
Isaac Corbrey
  • 553
  • 3
  • 20
4
votes
1 answer

Does Argument-Dependent Lookup go before normal scope lookup?

This is the code in question that appears in §13.3 of "C++ Primer", 5ed: void swap(Foo &lhs, Foo &rhs) { using std::swap; swap(lhs.h, rhs.h); // uses the HasPtr version of swap // swap other members of type Foo } The book mentions the…
4
votes
1 answer

Using declaration refers into C, which is a base class (alias) of D, but it is not recognized as valid

This looks like an issue in clang (I've already opened a bug to clang), but I'd like to be sure that I'm not doing a mistake. Consider the following code: struct B { }; template struct D; template
skypjack
  • 49,335
  • 19
  • 95
  • 187
4
votes
1 answer

Using alias for reference to anonymous structure results in error

My theory is that gcc has a bug. The following compiles in both clang and gcc: using type = const struct {}&; But now when I change it to an rvalue reference it compiles with clang but not with gcc: using type = const struct {}&&; //…
template boy
  • 10,230
  • 8
  • 61
  • 97
4
votes
2 answers

Conflict between Using Declaration and Forward Declaration

Lets go for a walk with Bulldog :) Say I have a namespace Street::House (inside namespace Street) where the class Bulldog is declared (let it be in House/Bulldog.hpp): namespace Street { namespace House { class Bulldog {}; } } Then, I have the…
3
votes
1 answer

Is a using declaration for a non-member type equivalent to an alias declaration with an identifier equal to the terminal name of the using declarator?

In short, I'm asking if doing using foo::bar::baz; has the same effect as using baz = foo::bar::baz; (Clearly I'm assuming that foo::bar::baz names a type that is not a class member, e.g. I'm referring to something like namesapce foo::bar { using…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
1 answer

What are the access specifiers of inherited (-> "using") base class ctors / operators in derived class?

In the following code you can see that I'm inheriting the base class ctors into the derived class under the "private" access specifier. My initial thought would be that these would adapt to the access specifiers that I have given (here "private")…
3
votes
3 answers

Why using declaration is needed when an overload is deleted

Why do I have to reintroduce the name of a function having some of its overloads deleted ? #include struct A { void f(int) {} void f(double) {} void f(const std::string&) {} }; struct B : public A { using A::f; // needed…
SR_
  • 874
  • 13
  • 31
3
votes
1 answer

Can you use using to redeclare a public member in base class as private in derived class?

This code snippet demonstrating changing class member access came from IBM. struct A { protected: int y; public: int z; }; struct B : private A { }; struct C : private A { public: using A::y; using A::z; }; struct D : private A…
Mode77
  • 991
  • 8
  • 28
3
votes
2 answers

Why can't a typedef type be used to declare its parent class' ctors?

template struct A { int n; A(bool) {} }; template struct B { struct C : A { using Base = A; using A::A; // ok using Base::n; // ok // error: dependent using…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
3
votes
4 answers

C++ using declaration for parameter pack

I would like to define a class which inherits from a bunch of classes but which does not hide some specific methods from those classes. Imagine the following code: template class SomeClass : public Bases... { public: using…
Bernd
  • 2,113
  • 8
  • 22
3
votes
1 answer

Surprising behavior in multiple copy constructor inheritance

Starting with C++11, there can be two copy constructors, one taking a parameter of type T&, and one taking a parameter of type const T&. I have a situation where (seemingly) adding a second copy constructor causes neither one to get called, when the…
Dan R
  • 1,412
  • 11
  • 21