Questions tagged [using-declaration]

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

164 questions
1
vote
0 answers

Alias for user defined literal, i.e. 'using NS::operator ""_suffix' with another name

Consider that some library defines: namespace NS { constexpr atype operator ""_suffix(const char*, std::size_t); }; If I don't like the name _suffix (maybe it clashes with some other library, or it is in stark contrast with my naming…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
1
vote
2 answers

How do I template a function typedef using an alias declaration?

I'm simply trying to convert my current typedef: typedef void (Foo::*CallbackName)(int arg); Into a function alias, which I have looking like: template using T_CallbackName = void(T::*CallbackName)(int arg); Is this correct? Alias…
Danny
  • 354
  • 3
  • 13
1
vote
1 answer

Why does std::add_lvalue_reference not behave as expected?

#include template using Ref1 = T & ; template using Ref2 = std::add_lvalue_reference_t; template void f1(Ref1) {} template void f2(Ref2) {} int main() { int n{}; …
xmllmx
  • 39,765
  • 26
  • 162
  • 323
1
vote
4 answers

Declaring using statement after namespace declaration

I am writing a utility library which is made up of several "Packages". The classes in each package are contained in various namespaces. I have an idea as to how I can simplify the situation by automatically declaring using statements at the end of…
Dave
  • 7,283
  • 12
  • 55
  • 101
1
vote
3 answers

namespace composition and selection

After reading The C++ Programming Language 4th edition (section 14.4.4 - Composition and Selection) I thought that the following program would compile correctly: #include namespace foo { int var = 0; // more…
carlo
  • 325
  • 1
  • 4
  • 12
1
vote
2 answers

Why is the move constructor not inhereted by using declaration

In the following code the move constructor of the derived class is obviously not generated although the base class is move constructible. #include #include #include #include template class…
Marcel
  • 1,688
  • 1
  • 14
  • 25
1
vote
0 answers

Policy class with template alias

I am not sure whether the question title is right. I am looking for a method to choose one of the template specializations of class A based on template alias from policy class. Is there any way to achieve this ? // g++ -Wall -std=c++11 p.cpp…
1
vote
2 answers

Using-declaration to move name to another namespace?

Given: namespace One { void foo(int x) { munch(x + 1); } }; namespace Two { // ... see later } ... void somewhere() { using namespace Two; foo(42); ... is there any difference between the following two variants: a) namespace Two…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
1
vote
1 answer

Example of error caused by using directive in namespaces

I'm trying to understand what kind of errors could arise from including using declarations in namespaces. I'm taking into account these links. I'm trying to create an example where an error is being caused by a name being silently replaced by an…
swahnee
  • 2,661
  • 2
  • 24
  • 34
1
vote
0 answers

Use of Elaborated Type Specifier to create object of hidden class

I have following code snippet : namespace A { class X { X() { std::cout<< " I am here in Constructor"; } }; } namespace B { void X(int) { …
1
vote
0 answers

Is there a work-around for parameter pack expansion in using declarations

Parameter pack expansion in using declarations is not supported in C++14, and so the following code fails to compile: template struct A { virtual void foo(T); }; template struct B: public A... { using…
Jens
  • 9,058
  • 2
  • 26
  • 43
1
vote
0 answers

Visual Studio 2015 bug? Ambiguous member function access, order of ancestor classes overrides using statement

Am I missing something, or did I find a Visual Studio bug? Bugs aside, is using this type of inheritance OK or evil? GCC 4.9.0 produces my expected results: base.getProperty() 1 otherBase.getProperty() 2 derivedA.getProperty()…
user1902689
  • 1,655
  • 2
  • 22
  • 33
1
vote
0 answers

Using redeclaration within a block scope

Here is the code which causes a compile-time error: #include int a; void f() { using ::a; using ::a; //'a' is already declared in this scope. } int main(){ } DEMO What the standard says is (N4296::7.3.3/10…
user2953119
1
vote
1 answer

Calling an aliased-declared base class constructor in a different namespace

I am trying to understand some details of alias-declared classes through C++11's using and how/why this affects a base class constructor call. Example Code #include namespace N { template struct Foo { // Foo(){};…
hcc23
  • 1,180
  • 11
  • 17
1
vote
1 answer

include and using declaration

using ::bb::cascades::Application; #include What do these two declaration mean? And are there any good tutorials which states the using directive/declaration deeply?Thanks.
Tahlil
  • 2,680
  • 6
  • 43
  • 84