Questions tagged [using-declaration]

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

164 questions
2
votes
2 answers

"Using declaration" not working in RADStudio 2010

I'm deriving a new class from the VCL TStream class: // A stream based on a temporary file, deleted when the stream is closed class TTempFileStream : public TStream { ... public: using TStream::Seek; __int64 __fastcall Seek(const __int64…
Roddy
  • 66,617
  • 42
  • 165
  • 277
1
vote
1 answer

C++ `using` keyword vs derived class

We have a templated type Foo. 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 keyword (using FooA = Foo) vs declaring an empty derived…
maattdd
  • 181
  • 2
  • 6
1
vote
0 answers

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.Collections.Generic.List to be clear). I used…
1
vote
1 answer

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 definition, no? Compare the following…
glades
  • 3,778
  • 1
  • 12
  • 34
1
vote
1 answer

Default argument for template not working

I have a chain of nested templated using declarations. It looks something like this: template class Foo { public: Foo() : value{0} {}; template
Seymore Glass
  • 53
  • 1
  • 4
1
vote
1 answer

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 ... return j; }; class B: public…
stustd
  • 303
  • 1
  • 10
1
vote
0 answers

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 function to have cout and end and the code…
lyu.l
  • 282
  • 3
  • 8
1
vote
2 answers

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 namespace X; what I imagine happening is if I use some…
1
vote
1 answer

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 struct base { using type = T; static constexpr int…
Vincent
  • 57,703
  • 61
  • 205
  • 388
1
vote
1 answer

C++ inheritance overloads functions with different parameters

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 paste since that's supposed to be what inheritance is…
1
vote
1 answer

the overload resolution of using base member function introduced into derived class

According to some quotes in standard: [over.match.funcs]/4 [...] For non-conversion functions introduced by a using-declaration into a derived class, the function is considered to be a member of the derived class for the purpose of defining the…
xmh0511
  • 7,010
  • 1
  • 9
  • 36
1
vote
2 answers

Function-definition in class requires same function in other class : compilation error

I have an enum class "Suit" and defined a function "string to_string(Suit e)" In another class, "Card", I have a member variable "my_Suit" and a member-function "to_string". This function calls the function "to_string" with "my_Suit" as a…
1
vote
3 answers

C++ "using" declaration in Visual Studio 2008

I am trying to use google protobuf and they have the following example: using google::protobuf; protobuf::RpcChannel* channel; protobuf::RpcController* controller; SearchService* service; SearchRequest request; SearchResponse response; void…
beepboopbeep
1
vote
2 answers

How can I typedef a bound a member method and then use that type as a template parameter?

I'm trying to bind a method of a class and to pass it as a template parameter to a different class. This type needs to be used in multiple methods, so I tried using a using clause in the class (struct base below). However, I'm not really able to get…
Avi Ginsburg
  • 10,323
  • 3
  • 29
  • 56
1
vote
2 answers

using declaration: one more bug of gcc and clang?

Why do gcc HEAD 10.0.0 20190 and Clang HEAD 9.0.0 both reject this program? #include void g( int x ) { std::cout << "Hello g( " << x << " )\n"; } template void g() { std::cout << "Hello g( " << N << "…
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335