Here, I test to check a var defined by "typename D", is a unqualified dependant name. The answer is YES. since if i write its definition twice:
template<typename D>
class A {
D d_field;
D d_field;
void func() { d_field = 1000; }
}
int main()
{
return 0;
}
the g++ will report re-definition error. so that it demonstrates "d_field" is checked in template definition.
and if I give a type "double*" to use this template. The template instantiation happens, with an error reported in func2, "int can't be converted to double*".
template<typename D>
class A {
D d_field;
void func() { d_field = 1000; }
}
int main()
{
A<double*> a;
a.func();
return 0;
}
it prove that "d_field" will be check in template instantiation.
In addition, I change that as below, the g++ will compile it ok.It prove that gcc works in two-phase-lookup based on c++ standard... if the name is qualified dependant name, it will only be checked in template instantiation.
template<typename D>
class A {
D:: d_field;
D:: d_field;
void func() { d_field = 1000; }
}
int main()
{
return 0;
}
In a word, use a template parameter to define a variable in template, the variable's name is a unqualified dependant name.
is it right?