-5

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?

Cheeray
  • 1
  • 1
  • perhaps you answer is here http://stackoverflow.com/questions/8501294/different-behavior-for-qualified-and-unqualified-name-lookup-for-template – Marius Bancila Jan 29 '13 at 14:03
  • 2
    I have no idea what you’re asking, and **MAKING THE TEXT VERY LARGE AND BOLD** surprisingly doesn’t help. – Konrad Rudolph Jan 29 '13 at 14:04
  • 3
    Your question's text sounds like a proud, groundbreaking announcement of a historical discovery, with 99% of the arguments in huge, bold font, and a tiny tiny small question at the end. It should be the other way round. Give emphasis to the *question*, don't show off your deductions. – Andy Prowl Jan 29 '13 at 14:06
  • 1
    Your premises are wrong in that you are using the output of a compiler to determine what the standard dictates, but the standard leaves freedom for better/worse diagnostics in many places. The fact that the compiler complains does not mean that the standard mandates it, the fact that it does not complain does not mean that the standard allows it either (and the change in fonts makes it harder for me to read the question) – David Rodríguez - dribeas Jan 29 '13 at 14:42

1 Answers1

2

No. The variable's name is a locally declared name, so it is neither dependent nor non-dependent. Only names which the compiler has to look up outside of the template can be dependent or non-dependent.

James Kanze
  • 150,581
  • 18
  • 184
  • 329