Use of typename keyword with typedef and new

前端 未结 3 1585
北恋
北恋 2020-12-01 12:26

Consider this code,

template
struct Sample
{ 
     typename T::X *x; //declare pointer to T\'s X
};

In the above code, the key

3条回答
  •  执笔经年
    2020-12-01 13:16

    Your code seems to go into a very gray area.

    This paragraph on name hiding

    A class name (9.1) or enumeration name (7.2) can be hidden by the name of a variable, data member, function, or enumerator declared in the same scope. If a class or enumeration name and a variable, data member, function, or enumerator are declared in the same scope (in any order) with the same name, the class or enumeration name is hidden wherever the variable, data member, function, or enumerator name is visible.

    seems to indicate that the compiler is right to complain that A::X is not a type name.

提交回复
热议问题