Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
66 views

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 &...
Oersted's user avatar
  • 3,834
3 votes
1 answer
106 views

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::...
Pietro's user avatar
  • 13.5k
-2 votes
3 answers
189 views

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)...
int main's user avatar
2 votes
1 answer
104 views

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> ...
Bulletmagnet's user avatar
  • 6,091
2 votes
0 answers
109 views

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 ...
Igor G's user avatar
  • 2,668
3 votes
3 answers
169 views

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 ...
SoulfreezerXP's user avatar
0 votes
0 answers
74 views

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 ...
Igor G's user avatar
  • 2,668
0 votes
1 answer
144 views

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() { ...
ridilculous's user avatar
4 votes
1 answer
119 views

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 ...
xmllmx's user avatar
  • 44.6k
3 votes
1 answer
121 views

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); }...
AgainPsychoX's user avatar
  • 1,855
1 vote
0 answers
65 views

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 { ...
marikocat's user avatar
2 votes
2 answers
212 views

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 '...
Mark Borgerding's user avatar
0 votes
0 answers
59 views

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 ...
Ryan Keathley's user avatar
2 votes
2 answers
136 views

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; ...
Bulletmagnet's user avatar
  • 6,091
1 vote
2 answers
1k views

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<...
KcFnMi's user avatar
  • 6,367
3 votes
1 answer
197 views

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 ...
Enlico's user avatar
  • 30.3k
3 votes
1 answer
121 views

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 ...
glades's user avatar
  • 5,374
4 votes
2 answers
160 views

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:...
kstn's user avatar
  • 570
1 vote
1 answer
78 views

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 ...
maattdd's user avatar
  • 181
-2 votes
1 answer
258 views

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::...
awwd's user avatar
  • 31
1 vote
0 answers
481 views

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....
user avatar
0 votes
1 answer
99 views

(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 ...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
406 views

The following code #include <vector> #include <string> template<typename T> struct V : public std::vector<T> { using Impl = std::vector<T>; using typename Impl::...
Bulletmagnet's user avatar
  • 6,091
0 votes
2 answers
650 views

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 ...
glades's user avatar
  • 5,374
0 votes
0 answers
497 views

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, ...
antonio's user avatar
  • 483
1 vote
1 answer
165 views

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 ...
glades's user avatar
  • 5,374
1 vote
1 answer
354 views

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} {}; ...
Seymore Glass's user avatar
5 votes
1 answer
236 views

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(...
Jarod42's user avatar
  • 227k
5 votes
1 answer
121 views

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 ...
mada's user avatar
  • 2,033
2 votes
1 answer
418 views

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 ... ...
stustd's user avatar
  • 335
1 vote
0 answers
54 views

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 ...
lyu.l's user avatar
  • 312
1 vote
2 answers
145 views

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 ...
jaylse2's user avatar
  • 71
3 votes
3 answers
84 views

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&...
SR_'s user avatar
  • 927
5 votes
1 answer
342 views

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 "; } }; ...
Fady Hany's user avatar
  • 179
-1 votes
1 answer
573 views

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> ...
rTanna's user avatar
  • 31
0 votes
0 answers
37 views

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 ...
Talmid's user avatar
  • 15
5 votes
2 answers
290 views

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'...
康桓瑋's user avatar
  • 46.8k
2 votes
1 answer
540 views

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&...
Itachi Uchiwa's user avatar
-3 votes
2 answers
206 views

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-...
Vlad from Moscow's user avatar
1 vote
1 answer
691 views

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 { /* ... */ }; }; ...
康桓瑋's user avatar
  • 46.8k
0 votes
1 answer
101 views

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:...
Kaznov's user avatar
  • 1,193
2 votes
1 answer
123 views

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 ...
Colin Hicks's user avatar
0 votes
1 answer
380 views

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 ...
Alec Armstrong's user avatar
6 votes
0 answers
133 views

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; ...
Oliv's user avatar
  • 18.2k
3 votes
1 answer
397 views

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; ...
Mode77's user avatar
  • 1,083
1 vote
1 answer
499 views

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 ...
Vincent's user avatar
  • 61.1k
2 votes
2 answers
119 views

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 ...
Ansuman Mishra's user avatar
3 votes
2 answers
164 views

template<typename> struct A { int n; A(bool) {} }; template<typename> struct B { struct C : A<B> { using Base = A<B>; using A<B>::A;...
xmllmx's user avatar
  • 44.6k
2 votes
1 answer
261 views

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 ...
Hansondon's user avatar
1 vote
1 answer
957 views

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 ...
MaximV's user avatar
  • 325