Why does C++’s “using namespace” work the way it does?

Quoting an excerpt from C++ Primer (5th Edition) section “18.2.2. Using Namespace Members” The scope of names introduced by a using directive is more complicated than the scope of names in using declarations. As we’ve seen, a using declaration puts the name in the same scope as that of the using declaration itself. It is … Read more

Why does this dependent name lookup find a global identifier instead of the method?

To the best of my knowledge here’s what’s going on. DR228 says: [Voted into WP at April 2003 meeting.] Consider the following example: template<class T> struct X { virtual void f(); }; template<class T> struct Y { void g(X<T> *p) { p->template X<T>::f(); } }; This is an error because X is not a member … Read more

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

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

What is the fully qualified name of a friend function defined inside of a class?

Is argument-dependent lookup the only way val() can be found? Yes, it is the only way. To quote the holy standard at [namespace.memdef]/3: If a friend declaration in a non-local class first declares a class, function, class template or function template the friend is a member of the innermost enclosing namespace. The friend declaration does … 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

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

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

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş