178 questions
1
vote
1
answer
66
views
Why does the compiler accept a 'using' directive aliasing a template with an incomplete type?
I struggled with my question title... I hope it will be clearer with a snippet.
This is derived and simplified from Attorney-Client idiom.
File header_A.h
// forward declaration
struct B;
template &...
3
votes
1
answer
106
views
Can `using` work without specifying template parameters? [duplicate]
Is it possible to use using with a template class without specifying its template parameters straight away?
#include <array>
using MyArray = std::array<int, 5>;
using MyArrayT = std::...
-2
votes
3
answers
189
views
C++ define a type alias 'pointer to array' with keyword using (not typedef) [duplicate]
It is easy to achieve this with typedef:
typedef int (*ptr_arr)[]; // pointer to array
But how to alias the same type as ptr_arr by using C++ using keyword?
Also would be nice to see (good formatted)...
2
votes
1
answer
104
views
clang doesn't see base class constructors pulled in via type alias
This code is accepted by GCC (several versions) and refused by clang (also several versions):
struct ACS{};
template<typename Dep>
struct AD{};
template<typename Der, typename Dep>
...
2
votes
0
answers
109
views
Does declaration "using type = type;" change the meaning of type? [duplicate]
Given the following example, gcc prints a warning. clang accepts it just fine. Who's right?
From my point of view, type was an alias for int before using-declaration, and it still is an alias for int ...
3
votes
3
answers
169
views
Is using-declaration with an anonymous enum valid in modern C++
I know that the following typedef-based code works fine and is widely used:
class Example {
public:
typedef enum {
eOrdered,
eRandom
} tePoolOrder;
};
Clang-tidy has now ...
0
votes
0
answers
74
views
Clang compiler cannot find the definition of template introduced by using-declaration. gcc and msvc see no problem
I've hit a scenario where gcc and clang have different opinions on the same piece of code. To my best understanding of using-declarations and inline namespaces, clang is wrong.
Example below works as ...
0
votes
1
answer
144
views
Why is the function with a std::initializer_list parameter not found despite trying to bring it into consideration with a 'using' declaration
I'm trying to bring a function into consideration with a using declaration:
namespace n {
struct S {};
bool equal(S a, S b, std::vector<int> = {1,2}) { return false; }
}
int main() {
...
4
votes
1
answer
119
views
Why can't C++ using-declaration expose a protected member of base as a public member of derived?
As per cppref:
Using-declaration introduces a member of a base class into the derived
class definition, such as to expose a protected member of base as
public member of derived.
However, the ...
3
votes
1
answer
121
views
Ambiguity while working with namespaces: Can `using` single thing leak anything else?
I have problem with ambiguity while working with namespaces.
Code:
namespace app::hal {
enum class Motor {
Left = 0,
Right = 1
};
void setMotor(Motor which, float duty);
}...
1
vote
0
answers
65
views
The using-declaration for inheriting constructors [duplicate]
I'm strugling to understand why I'm getting a compilation error in the example below:
class Shape
{
protected:
Shape() : num(0) {}
Shape(int i) : num(i) {}
public:
int getNum() const { ...
2
votes
2
answers
212
views
hiding a parent class but not the grandparent in C++
Is it possible to skip a generation with regards to class visibility?
The following works for gcc compilers but not clang nor intel. They fail with error: cannot cast 'C' to its protected base class '...
0
votes
0
answers
59
views
C++ autocomplete for dependent types
I'm using gcc-13 and VSCode with intellisense. It does a good job with typed auto complete of members and functions.
template <typename State>
concept IsPerfectInfoState = requires(
State ...
2
votes
2
answers
136
views
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;
...
1
vote
2
answers
1k
views
Using declaration in class refers into 'std::', which is not a class [duplicate]
I'm trying to unlearn using namespace std, considering https://www.youtube.com/watch?v=MZqjl9HEPZ8
So I tried
// using namespace std;
struct Data
{
using std::shared_ptr;
shared_ptr<...
3
votes
1
answer
197
views
Is a using declaration for a non-member type equivalent to an alias declaration with an identifier equal to the terminal name of the using declarator?
In short, I'm asking if doing
using foo::bar::baz;
has the same effect as
using baz = foo::bar::baz;
(Clearly I'm assuming that foo::bar::baz names a type that is not a class member, e.g. I'm ...
3
votes
1
answer
121
views
What are the access specifiers of inherited (-> "using") base class ctors / operators in derived class?
In the following code you can see that I'm inheriting the base class ctors into the derived class under the "private" access specifier. My initial thought would be that these would adapt to ...
4
votes
2
answers
160
views
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:...
1
vote
1
answer
78
views
C++ `using` keyword vs derived class
We have a templated type Foo<T>.
In the codebase, it's 99% instantiated with a couple of types, and I would like to use a distinct name for those cases.
What are the pros/cons of the using ...
-2
votes
1
answer
258
views
usage of using keyword in struct C++ [duplicate]
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::...
1
vote
0
answers
481
views
How to use "using static" with generic classes?
C# has an using static directive since C# 6.0 which is allows to includes more specific things (like classes, interfaces etc.) than namespaces. Well, I tried to include generic type class (System....
0
votes
1
answer
99
views
What's the relevance of the Note in [over.load]/1?
(You might see this question as a duplicate of this, but, to be honest, I've not really understood the matter, so I'm asking separately with my own wording.)
[over.load]/1 reads:
Not all function ...
2
votes
1
answer
406
views
clang doesn't see base class constructors pulled in via typedef
The following code
#include <vector>
#include <string>
template<typename T>
struct V : public std::vector<T>
{
using Impl = std::vector<T>;
using typename Impl::...
0
votes
2
answers
650
views
Forward declare using directive for recursive definitions
I have an array with items of type variant that I want to iterator over using the generic std::array iterator. Now I want to do the management of the array with my own class array2. However, the ...
0
votes
0
answers
497
views
Should I put my using declarations in the unnamed namespace?
When implementing a function in CPP, I am used to put my helper functions in an anonymous namespace, so they don't pollute the global namespace outside the CPP file where they are defined.
However, ...
1
vote
1
answer
165
views
Does the using declaration allow for incomplete types in all cases?
I'm a bit confused about the implications of the using declaration. The keyword implies that a new type is merely declared. This would allow for incomplete types. However, in some cases it is also a ...
1
vote
1
answer
354
views
Default argument for template not working
I have a chain of nested templated using declarations. It looks something like this:
template <typename A, typename B, typename C, typename D>
class Foo {
public:
Foo() : value{0} {};
...
5
votes
1
answer
236
views
How to use using-declarations in constraint
Is there an alternative to have some using-declarations in concept/constraint? Something like:
template <typename T>
concept has_begin_v0 = requires (T t)
{
using std::begin; // KO
begin(...
5
votes
1
answer
121
views
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
...
2
votes
1
answer
418
views
Observation (check): same member function name, different signature, one as virtual member
I'm afraid this is not possible:
class A {
public:
A(){}
virtual string s() = 0
string s(int i) {
auto j = this->s();
... modify j ...
...
1
vote
0
answers
54
views
Issues with C++ namespace across file and using directive
Here are a demo code from C++ primer plus about using using-directive and using-declaration across header files and cpp files, I've made some modification to remove the using declarations in other ...
1
vote
2
answers
145
views
Extremely basic question about namespaces in c++
using namespace X;
cout << var;
using Y::var;
cout << var;
So say I have a namespace X and a namespace Y that both contain a variable of type int called var. When I say using ...
3
votes
3
answers
84
views
Why using declaration is needed when an overload is deleted
Why do I have to reintroduce the name of a function having some of its overloads deleted ?
#include <string>
struct A
{
void f(int) {}
void f(double) {}
void f(const std::string&...
5
votes
1
answer
342
views
Why is this compiling successfully?
What is the reason which why this code compile :
#include <iostream>
using namespace std;
class being {
public:
void running(char c) {
cout << "No one know ";
}
};
...
-1
votes
1
answer
573
views
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::string, std::string>;
std::shared_ptr<ArgsMap> ...
0
votes
0
answers
37
views
C++ : Inheriting from lambdas, overload resolution "quirk" [duplicate]
Why is the using-declaration inside struct S necessary?
struct S inherits from both l1's and l2's types, which means their respective operator()s are considered when calling s(123). This is ...
5
votes
2
answers
290
views
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:
<source>:4:12: error: reference to 'A'...
2
votes
1
answer
540
views
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&...
-3
votes
2
answers
206
views
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-...
1
vote
1
answer
691
views
Can C++20 using enum apply to templates?
According to cppreference, both gcc and msvc have completed the implementation of C++20 feature using enum, which means we can using-declaration with an enum:
struct A {
enum e { /* ... */ };
};
...
0
votes
1
answer
101
views
How can I introduce base class member to derived class definition, but only one overload?
With 'using declarations' I can introduce a base class member into definition of my class:
class Base {
public:
void baseMemberFn();
/* ... */
};
class Derived : private Base {
public:...
2
votes
1
answer
123
views
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 ...
0
votes
1
answer
380
views
PowerPoint VBA - Declaring Arrays in the Declaration
I would be grateful if someone could tell me if I am declaring my arrays properly in my declaration statement so that they will be available in all of the macros and program.
With PowerPoint VBA my ...
6
votes
0
answers
133
views
Using constrained template base member function in derived class, which one should be hidden?
Let's consider the code bellow where base members are declared in the derived class. GCC and Clang do not agree on which member is going to be hidden:
template <class T>
concept C = true;
...
3
votes
1
answer
397
views
Can you use using to redeclare a public member in base class as private in derived class?
This code snippet demonstrating changing class member access came from IBM.
struct A {
protected:
int y;
public:
int z;
};
struct B : private A { };
struct C : private A {
public:
using A::y;
...
1
vote
1
answer
499
views
Using syntax to expose base class alias templates and variable templates in derived class?
Consider a base template class and a derived template class in a heavy template metaprogramming context (simplified here for readability and to focus on the problem).
template <class T>
struct ...
2
votes
2
answers
119
views
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 ...
3
votes
2
answers
164
views
Why can't a typedef type be used to declare its parent class' ctors? [duplicate]
template<typename>
struct A
{
int n;
A(bool)
{}
};
template<typename>
struct B
{
struct C : A<B>
{
using Base = A<B>;
using A<B>::A;...
2
votes
1
answer
261
views
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 ...
1
vote
1
answer
957
views
C++ inheritance overloads functions with different parameters [duplicate]
I am working on a project which uses class inheritance and requires lots of overloads in both the base and derived class, I have simplified the code, but I wouldn't want to unnecessarily copy and ...