Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Переопределение типа


Автор: DTF 3.1.2011, 20:48
Добрый вечер.

Есть код
Код

template< typename TemplateParam >
class MyClass
{
};

class A
{
public:
   typedef MyClass<A> MyClass;

   MyClass Method() 
   { 
      return MyClass(); 
   }
};

int main()
{
   A a;
   a.Method();

   return 0;
}


на MSVC 10 он компилируется нормально, а g++ почему-то ругается на то, что MeClass переопределен через typedef. Хотя, по идее, этот typedef должен создавать тип A::MyClass, и не задевать ранее определенный MeClass.

Подскажите плс, почему g++ такое не переваривает?

Автор: mes 4.1.2011, 18:27
Цитата( ISO/IEC 14882:2003)

3.3.6 Class scope
...
2) A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the
completed scope of S.
...
5) The potential scope of a declaration that extends to or past the end of a class definition also extends to
the regions defined by its member definitions, even if the members are defined lexically outside the
class 
...
Example :
...
Код

typedef int I;
class D {
typedef I I; // error, even though no reordering involved
};



Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)