Use this tag for questions related to the 'using' keyword in C++.
Questions tagged [using-declaration]
164 questions
2
votes
2 answers
GCC does not see function introduced from base class as ambiguous
The following code
struct Foo{};
struct Bar{};
struct Base {
Foo func1(const Foo , const Bar = Bar{}) const {
return {};
};
};
struct Derived : public Base {
using Base::func1;
Foo func1(const Foo ) const {
return…

Bulletmagnet
- 5,665
- 2
- 26
- 56
2
votes
1 answer
clang doesn't see base class constructors pulled in via typedef
The following code
#include
#include
template
struct V : public std::vector
{
using Impl = std::vector;
using typename Impl::vector; // the constructors
};
int main()
{
std::string empty;
…

Bulletmagnet
- 5,665
- 2
- 26
- 56
2
votes
1 answer
Using declaration and multiple inheritance
We know that a 'using declaration' for a namespace's member name in a scope where another entity is defined there with the same name, causes a compile time error: "symbol x is already defined".
The error is detected at the point the 'using…

Itachi Uchiwa
- 3,044
- 12
- 26
2
votes
1 answer
Rules regarding using declarations c++
After reading the accepted answer from this question, I thought I understood why the program failed, since the using directive does not actually declare the entity i in the region. However names introduced by a using declaration can be used just…

Colin Hicks
- 348
- 1
- 3
- 13
2
votes
2 answers
Function hiding in c++
I was trying out few concepts of function hiding in c++.
So here in the derived class I've used scope resolution operator using base::fun to provide scope of base class in derived class. My objective is to print cout<<" base "<< x; but the output…

Ansuman Mishra
- 49
- 1
- 6
2
votes
1 answer
Why does using-declared inheriting constructor NOT initialize the virtual base class using a default constructor?
I stumbled upon a question of the using-declared inheriting constructor yesterday. And after carefully reading the answer as well as the linked standard draft N3337, I found there might be some inconsistency (or at least my misunderstanding) when…

Hansondon
- 23
- 4
2
votes
1 answer
Variadic base class using declaration fails to compile in MSVC
I'm trying to implement a variadic visitor class.
template
class VisitorBaseFor {
protected:
virtual ~VisitorBaseFor() = default;
public:
virtual void visit(T &t) = 0;
};
template
class VisitorBase : public…

Julian Wiesler
- 55
- 4
2
votes
2 answers
Conflicting overloads with using-declaration
#include
struct A {
void test() { std::cout << "A\n"; }
};
struct B : A {
void test() { std::cout << "B\n"; }
};
struct C : B {
using A::test;
using B::test;
};
int main() {
C().test(); // Is this ambiguous?
return 0;
}
In…

TimK
- 4,635
- 2
- 27
- 27
2
votes
1 answer
What's the using equivalent of a function typedef?
How can I use the new1 using keyword to declare a function type?
I know how I can use it to declare a function pointer type. For example, the following typedef:
typedef int (*int_to_int)(int);
seems equivalent to the following using…

BeeOnRope
- 60,350
- 16
- 207
- 386
2
votes
1 answer
[[deprecated]] incompatible with using but compatible with typedef
I discovered (with g++ 6.3) that I can use the [[deprecated]] attribute to deprecate a typedef ([[deprecated]] typedef longname shortname;) but not a using declaration ([[deprecated]] shortname = longname;).
So I was wondering, is this intended (if…

pseyfert
- 3,263
- 3
- 21
- 47
2
votes
1 answer
C++ Immutability through a type alias
Is it wrong, okay or a good practice to use a using declaration to make an immutable version of a type ?
struct MutableA
{
int i;
float f;
};
using ImmutableA = const MutableA;
For pointer or ref members a wrapper like propagate_const would…

Michel
- 338
- 1
- 13
2
votes
1 answer
How to use `using space::function` in class declaration scope?
I would like to use a using declaration to enable ADL on a specific function lookup so that I can use it in a constructor initialization list.
Here is the code:
template< typename T >
struct RefWrapper
{
RefWrapper(T& t)
: w(t)
{}
…

v.oddou
- 6,476
- 3
- 32
- 63
2
votes
3 answers
Forward Definitions and namespace using
I am wondering about the meaning of the following lines of code in a header file...
Firstly I have the standard using which makes a class from a namespace visible to my code
using mynamespace::myclass;
and then a forward declaration of the same…

Ferenc Deak
- 34,348
- 17
- 99
- 167
2
votes
3 answers
Why there's no ambiguity in the expression `d.f(1);` below in main()?
Why there's no ambiguity in the expression d.f(1); below in main() between Base::f(int) and Derived::f(int) ?
class Base
{
public:
void f(int i) {}
void f(int i, int j) {}
};
class Derived : public Base
{
public:
using Base::f;
…

Belloc
- 6,318
- 3
- 22
- 52
2
votes
1 answer
Templates with same signature not causing a compiler error
The following program defines two function templates, A::foo<>() and B::foo<>(), in two separate namespaces (A and B). The two function templates are identical in signature, and differ only in the default argument assigned to their second template…

Andy Prowl
- 124,023
- 23
- 387
- 451