Questions tagged [using-declaration]

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

164 questions
3
votes
1 answer

Using namespace inside decltype

I have a function that looks more or less like this: template auto f(C const& c) -> decltype(begin(c)){ using std::begin; return begin(c); } The body of the function exploits the "using and use" idiom and thanks to the decltype,…
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
1 answer

What's the differences between `int*[1]` and `int(*)[1]`?

using T1 = int*[1]; using T2 = int(*)[1]; T1 t1; T2 t2; t1[0] = 0; // ok t2[0] = 0; // error : array type 'int [1]' is not assignable t2 = t1; // error : array type 'int [1]' is not assignable t2 = &t1; // error : array type 'int [1]'…
szxwpmj
  • 465
  • 2
  • 10
3
votes
2 answers

Why can an (irrelevant) using declaration reconcile overload ambiguity with Argument-Dependent Lookup?

This is a follow up of the question here on function overload with Argument-Dependent Lookup (ADL). I wanted to check my understanding of the rules under these circumstances so I wrote some test code. First, there is no swap for HasPtr class in std,…
3
votes
1 answer

Using declaration contains unexpanded parameter pack

How do I get this code to compile? struct type1 {}; struct type2 {}; struct handler1 { void handle(type1){} }; struct handler2 { void handle(type2){} }; template struct TheHandler : Handlers... { using…
Nikola Smiljanić
  • 26,745
  • 6
  • 48
  • 60
3
votes
3 answers

Is it possible to "bundle" template parameters in C++?

Is there a way to "bundle" template parameters together to avoid repetition? I have several classes and functions that all use the same three template parameters. It is not unusual to have a function that uses each class/function once. The…
Zack
  • 6,232
  • 8
  • 38
  • 68
3
votes
1 answer

Q_ENUMS and using declarations do not work together

Consider the following class definition: // exported.hpp #include class Exported: public QObject { Q_OBJECT public: using QObject::QObject; enum class FOO { BAR }; Q_ENUM(FOO) }; And the following main file: //…
skypjack
  • 49,335
  • 19
  • 95
  • 187
3
votes
0 answers

Name conflicts not detected when using aliases

This is a follow up to this question. Consider the following example: #include namespace MyProject { class string { public: string() { std::cout << "Callin string constructor" << std::endl; } }; } namespace Other { …
swahnee
  • 2,661
  • 2
  • 24
  • 34
3
votes
1 answer

C++ using declaration and argument dependent lookup

Is the code below valid C++98 or does it require a newer version of the C++ standard? namespace basic { void f(int) {} } namespace lib { template void g(T1 x1, T2 x2) { using basic::f; // pull in function f for basic…
3
votes
2 answers

How does unqualified name lookup work when using using-declarations?

Is this ill-formed or well-formed according to the c++ standard? namespace M { struct i {}; } namespace N { static int i = 1; } using M::i; using N::i; int main() { sizeof (i); } Clang rejects it and GCC accepts it. According to [namespace.udir-6]…
3
votes
1 answer

Redefinition inconsistency in clang between struct and int

The following program gives no error when compiling with clang: namespace X { struct i {}; } namespace Y { using X::i; struct i {}; } int main() {} Let's use int instead of struct, then we get: namespace X { int i; } namespace Y…
3
votes
1 answer

Assignment operator overloads have similar conversions (only in VS)

I have a class hierarchy with three classes (A, B and C). A and B are base-classes, parametrized with the derived Type. Class C is derived from both, A and B. The class B provides an assignment operator for objects of type A and class C inherits…
3
votes
2 answers

What the author is trying to say in GotW #53?

This pseudo-code was obtained from GotW #53 under the subtitle "A Not-So-Good Long-Term Solution". I've been trying to understand for a few hours already what the author is saying, specially in relation to the comment starting with "// error:…
Wake up Brazil
  • 3,421
  • 12
  • 19
3
votes
2 answers

Inheriting parent assignment operator when child's is implicitly deleted

In GCC 4.6, it is possible to inherit a parent's assignment operators even when the child's assignment operators are implicitly deleted due to a move constructor. In later versions of GCC (as well as Clang), this is no longer possible. What is the…
rcv
  • 6,078
  • 9
  • 43
  • 63
3
votes
1 answer

Does a using-declaration only import overloads declared above the using-declaration?

For example, GCC and clang both fail to compile the following code: struct S {}; namespace N { void g(S); } using N::g; namespace N { void g(int); } int main() { g(0); } with the error: test.cpp: In function 'int…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
2
votes
4 answers

How to use 'Using' keyword in ASP.NET page without code behind

I want to include some namespaces with their classes in my asp.net application. It is possible with using keyword ? I have this: <% …
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221