Use this tag for questions related to the 'using' keyword in C++.
Questions tagged [using-declaration]
164 questions
0
votes
1 answer
Template Template Parameters: What rule is applied in the following example
Assume the following example
using namespace std;
template class>
struct X
{
X()
{
std::cout << "1";
}
};
template
struct Y {};
template
using Z = Y;
template <>
struct X
…

getsoubl
- 808
- 10
- 25
0
votes
1 answer
Inline using how to make use of it
In C# one can type the using verb in line width the code sometimes, like
using (textwriter){ ..... }
I like that writing style and am wondered what is required to allow that for my own Api's.

Peter
- 2,043
- 1
- 21
- 45
0
votes
2 answers
c++ : comma separated list in using declaration
Why is it a bad practice to use a comma separated list in a using declaration statement in c++?
For example
using std::cout;
using std::cin;
using std::endl;
is considered better code than
using std::cout,std::cin,std::endl;
Some compiliers(gcc,…

iambrj
- 71
- 2
- 9
0
votes
2 answers
passing a parameter pack over a legacy function signature using forward_as_tuple
In my app I would like to pass in a parameter pack over a legacy function signature, and change the values. Here is code that illustrates my question with my attempts as comments:
#include
#include
void LegacySignature( void*…

rtischer8277
- 496
- 6
- 27
0
votes
1 answer
how to remove duplicate template arguments in template declaration
For conciseness sake I would like to name a template argument only once in its explicit instantiation, but I am getting a compiler error. I am attempting to use the C++ syntax as described in cppreference under Type alias, alias template. Here is my…

rtischer8277
- 496
- 6
- 27
0
votes
2 answers
effects of using declaration on name lookup for two exactly same names
Basically, my question is related to name lookup and using declaration (http://en.cppreference.com/w/cpp/language/namespace).
Suppose we have the following (definitely stupid) codes:
class Base {
public:
void fun()
{std::cout << "Base…

Changgong Zhang
- 167
- 1
- 5
0
votes
1 answer
What's wrong with this usage of a template `using` declaration
What's wrong with the following usage of a template using declaration?
template struct A {
template
using MyTemplate = A;
};
template struct B {
using MyType =…

AlwaysLearning
- 7,257
- 4
- 33
- 68
0
votes
1 answer
Why the need for a using-declaration naming a constructor?
Both paragraphs, 7.3.3.p1 and p3, in the C++11 Standard, make reference to a using-declaration naming a constructor. Why is this necessary? The code below shows that the base class A's constructors are seen in the derived class B as expected.
class…

Belloc
- 6,318
- 3
- 22
- 52
0
votes
2 answers
Why using cannot be used to define a virtual function?
I've recently discovered the use of using to import a base class function into the namespace of a derived class (when it is being hidden). I was trying to use it to import a function from a base class as an implementation of the function in a…

Vincent Fourmond
- 3,038
- 1
- 22
- 24
0
votes
3 answers
Inheritance and hiding parent's attributes
Is it reasonable to do something like this?
Note: this is a Minimal Working Example
class A {
public:
int getX() { return x; }
protected:
int x;
virtual void setX(int newX) = 0;
};
// Children can modify X
class…

Svalorzen
- 5,353
- 3
- 30
- 54
-1
votes
1 answer
How can I use an alias thats defined in a header file, in the return type (signature) of a function in the .cpp file?
I have a class, Tracker, where I declare an alias
From Tracker.h:
class Tracker {
...
using ArgsMap = std::unordered_map;
std::shared_ptr getArgsMapForTask(std::string task);
...
}
In the .cpp file, where I define…

rTanna
- 31
- 5
-2
votes
1 answer
usage of using keyword in struct C++
I created an exception like this in my header_file run.h
struct invalid_assignment : std::runtime_error {
using std::runtime_error::runtime_error;
};
I dont understand the using std::runtime_error::runtime_error; part.
This looks unecessary.

awwd
- 19
- 5
-2
votes
4 answers
why is this not out of scope
var smtp = new SmtpClient
{
Host =smtpHost,
Port = smtpPort,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address,…

Simon N
- 27
- 3
-3
votes
2 answers
The using declaration and function default arguments
According to the C++ 17 Standard (10.3.3 The using declaration)
1 Each using-declarator in a using-declaration98 introduces a set of
declarations into the declarative region in which the
using-declaration appears.
and
10 A using-declaration is a…

Vlad from Moscow
- 301,070
- 26
- 186
- 335