Questions tagged [using-declaration]

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

164 questions
1
vote
1 answer

override an overload selected by ADL

I'm using a library with a defective operator<<, which I want to replace with my own version. It follows the idiom where ADL selects the overload based on the argument's membership in the library's namespace. Is there any way to cause C++ to select…
0
votes
0 answers

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 concept IsPerfectInfoState = requires( State obj, typename State::Types::VectorAction &vec, …
0
votes
2 answers

Using declaration in class refers into 'std::', which is not a class

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 m_name = nullptr; // …
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
0
votes
1 answer

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 declarations can be overloaded. Those that cannot be…
0
votes
2 answers

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 variant might also contain an object of type array2…
0
votes
0 answers

Should I put my using declarations in the anonymous 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, the same doesn't seem to apply to using…
Antonio
  • 355
  • 1
  • 2
  • 13
0
votes
0 answers

C++ : Inheriting from lambdas, overload resolution "quirk"

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 corroborated by the fact that, once I remove using, gcc…
0
votes
1 answer

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 { /* ... */ }; }; struct S { using enum A::e; }; But when I…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
0
votes
1 answer

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: using Base::baseMemberFn; }; However, in…
Kaznov
  • 1,035
  • 10
  • 17
0
votes
1 answer

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 understanding is that if you want to access…
Alec Armstrong
  • 655
  • 1
  • 5
  • 10
0
votes
2 answers

Why can't I declare a variable or function more than once with different types?

Okay I know "One Definition Rule", but when I try to declare a variable with different types subsequently in source code, I run into some mistake like following: int fkc(); void fkc(); enter image description here I mean these two statements are…
0
votes
1 answer

"Entities with the same name defined in an outer scope are hidden" does not hold

In book "C++ Primer" fifth edition, there is a line "Entities with the same name defined in an outer scope are hidden" in the second page of Section 18.2.2. This sentence is underlined with red as follows: I tried to repeat the claim in an…
user5280911
  • 723
  • 1
  • 8
  • 21
0
votes
1 answer

Using-declaration of an existing type from base class vs creating a type alias inside child class

I would like to provide access to an existing type from base class inside child class. I found two different ways : struct A { typedef int mytype; }; struct B { typedef double mytype; }; I can "include" the type with a using declaration…
Baptistou
  • 1,749
  • 1
  • 13
  • 24
0
votes
0 answers

Using vs typedef in class

I thought the new using syntax in C++11 and typedef were equivalent (except for templates). But it seems that with using it is also not possible to declare a class member. class A { //... Public members private: typedef std::vector
evolved
  • 1,850
  • 19
  • 40
0
votes
2 answers

Why in member function implementation result type can't be described by using defined in class?

Refactoring some code, I found, that if I have member function definition outside of the class, it's return type can't use names defined by "using" inside this class. #include class Foo { public: using Bar = int; Bar f(); }; Bar…
Kaznov
  • 1,035
  • 10
  • 17
1 2 3
10
11