GCC issue: using a member of a base class that depends on a template argument

David Joyner had the history, here is the reason. The problem when compiling B<T> is that its base class A<T> is unknown from the compiler, being a template class, so no way for the compiler to know any members from the base class. Earlier versions did some inference by actually parsing the base template class, … Read more

Propagating ‘typedef’ from based to derived class for ‘template’

I believe that this question is duplicate, but I cannot find it now. C++ Standard says that you should fully qualify name according to 14.6.2/3: In the definition of a class template or a member of a class template, if a base class of the class template depends on a template-parameter, the base class scope … Read more

Why doesn’t ADL find function templates?

This part explains it: C++ Standard 03 14.8.1.6: [Note: For simple function names, argument dependent lookup (3.4.2) applies even when the function name is not visible within the scope of the call. This is because the call still has the syntactic form of a function call (3.4.1). But when a function template with explicit template … Read more

In a templated derived class, why do I need to qualify base class member names with “this->” inside a member function?

C++ answer (general answer) Consider a template class Derived with a template base class: template <typename T> class Base { public: int d; }; template <typename T> class Derived : public Base<T> { void f () { this->d = 0; } }; this has type Derived<T>, a type which depends on T. So this has … Read more

Derived template-class access to base-class member-data

You can use this-> to make clear that you are referring to a member of the class: void Bar<T>::BarFunc () { std::cout << this->_foo_arg << std::endl; } Alternatively you can also use “using” in the method: void Bar<T>::BarFunc () { using Bar<T>::_foo_arg; // Might not work in g++, IIRC std::cout << _foo_arg << std::endl; } … Read more

What is “Argument-Dependent Lookup” (aka ADL, or “Koenig Lookup”)?

Koenig Lookup, or Argument Dependent Lookup, describes how unqualified names are looked up by the compiler in C++. The C++11 standard ยง 3.4.2/1 states: When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (3.4.1) may be searched, and in those namespaces, namespace-scope friend function … Read more

tech