Questions tagged [using-declaration]

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

164 questions
6
votes
2 answers

using and overloading a template member function of a base class?

In the following, struct Y overloads X's member function f. Both overloads are template functions, but take different arguments (typename and int), to be explicitly specified: struct X { template static bool f() { return true;…
iavr
  • 7,547
  • 1
  • 18
  • 53
5
votes
1 answer

How to use using-declarations in constraint

Is there an alternative to have some using-declarations in concept/constraint? Something like: template concept has_begin_v0 = requires (T t) { using std::begin; // KO begin(t); /*..*/ }; The possible ways I have found…
Jarod42
  • 203,559
  • 14
  • 181
  • 302
5
votes
1 answer

Question on [over.match.funcs.general]/9 and inherited copy/move constructors

Per § 12.2.2.1 [over.match.funcs.general]/9-sentence-2: A constructor inherited from class type C ([class.inhctor.init]) that has a first parameter of type “reference to cv1 P” (including such a constructor instantiated from a template) is excluded…
mada
  • 1,646
  • 1
  • 15
5
votes
1 answer

Why is this compiling successfully?

What is the reason which why this code compile : #include using namespace std; class being { public: void running(char c) { cout << "No one know "; } }; class human :public being { public: using being::running; void…
5
votes
2 answers

Ambiguous name lookup with C++20 using-enum-declaration

Consider following code snippet with C++20 using-enum-declaration: namespace A { enum A {}; }; using namespace A; using enum A; gcc-trunk rejects it with: :4:12: error: reference to 'A' is ambiguous 4 | using enum A; | …
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
5
votes
0 answers

How to make all hidden names from a base class accessible in derived one?

Starting from this question: Pointer derived from pure virtual class(A) can't access overload method from the pure class (B) And considering this simplified code: #include #include class Abstract { public: virtual void…
j4x
  • 3,595
  • 3
  • 33
  • 64
5
votes
2 answers

Using-declaration of an existing namespace type vs creating a type alias

This is not a question about the difference between using and typedef for creating type aliases. I would like to provide access to an existing type from a namespace inside a code block or a function. I found two different ways : I can "include" the…
Baptistou
  • 1,749
  • 1
  • 13
  • 24
5
votes
1 answer

New wording for [namespace.memdef]/1

I believe the new wording for [namespace.memdef]/1 tries to explain the conflict between the two declarations using M::g; and void g(); in namespace X, but I fail to understand the relationship between this new wording and the alluded conflict. A…
João Afonso
  • 1,934
  • 13
  • 19
5
votes
1 answer

Override public virtual function with private base function?

Let's consider two classes A and B with the following interface: class A { public: virtual void start() {} //default implementation does nothing }; class B { public: void start() {/*do some stuff*/} }; and then a third class which inherits…
JBL
  • 12,588
  • 4
  • 53
  • 84
5
votes
0 answers

Implementation divergence for program with multiple inheritance and using-declaration with different access specifier than original declaration

Is the following program well-formed or ill-formed according to the c++ standard? struct A { protected: static const int x = 0; }; struct B : A {}; struct C : A { using A::x; }; struct D : B, C {}; int main() { D::x; } Different compilers gives…
5
votes
2 answers

Class declaration in same scope as using declaration compiles in GCC but not MSVS

Is the following program well-formed according to the c++ standard? namespace X { class A; } namespace Y { using X::A; class A {}; } int main() {} I'm getting different results with different compilers: gcc compiles it without errors. visual c++…
Supremum
  • 542
  • 7
  • 23
5
votes
1 answer

"using" with base class name to change access valid?

My friend has shown me the follow code struct A { virtual void f() = 0; virtual void g() = 0; }; struct AInternal : A { virtual void f() { /* ... */ } virtual void g() { /* ... */ } }; He is using AInternal as an internal class that…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
4
votes
3 answers

In C++ can one rename/alias a non-namespace, non-class name?

I have namespace src { struct src_bar; void src_baz(); template class src_qux; } which I'd like to reference as namespace dst { struct dst_bar; void dst_baz(); template class dst_qux; } meaning that I'd like…
Rhys Ulerich
  • 1,242
  • 1
  • 12
  • 28
4
votes
2 answers

alias constant in the inherited class

I have a base class defining a constant and the child class can use it using alias. The construct is as below class Base { protected: static const int A_ = 1; }; class Foo : public Base { private: using Base::A_; }; However, when I define…
kstn
  • 537
  • 4
  • 14
4
votes
3 answers

using declarations and const overloads

Suppose I have two versions of operator-> (overloaded on const) in a base class. If I say using Base::operator->; in a derived class, will I get access to both versions or just the non-const one?
fredoverflow
  • 256,549
  • 94
  • 388
  • 662