I am learning templates in C++. So reading examples from different sources(including SO). One such example whose statement i am unable to understand(or rather i think is incorrect) is given below:
class Base {
protected:
template <typename T1>
void print_pi() {
std::cout << (T1)3.141596 << std::endl;
};
};
template <typename T2>
class Derived : public Base {
};
template <typename T3>
class DoubleDerived : public Derived<T3> {
public:
void test() {
print_pi<int>(); // This creates error, however changing to Base::print_pi<int>(); works.
}
};
The user of the accepted answer says:
In the class Derived the name print_pi is a dependent name.
My question is that isn't print_pi
a non-dependent name? I mean it doesn't doesn't depends on a template parameter. For instance, print_pi<T>
is a dependent name but in OP's code inside the derived class DoubleDerived
the name print_pi
is non-dependent IMO. Can someone tell me why the user says that print_pi
is a dependent name. I mean even print_pi<int>
is non-dependent. I was thinking of writing an answer there saying that print_pi
is a non-dependent name and according to Non-dependent name lookup members, the problem is that the compiler does not look in dependent base classes when looking up nondependent names but then some people closed the question.
Am i right in saying that the currently accepted answer is incorrect in saying that print_pi
is a dependent name?