I am quite sure that I read the reason why the compiler cannot handle this code somewhere in SO, but after several hours of searching I still can not find it. Here is the relevant code:
#include <iostream> template <typename T> class base { }; class derived : base<derived::myStruct> { public: struct myStruct { }; }; int main () { return 0; }
The problem is that the parser first tries to generate the base<derived::myStruct> before parsing derived , and thus I get this error: "error C2065:" myStruct ": undeclared identifier". As a silly trick, I noticed that VS2010 stops complaining if I declare struct myStruct; just above class derived . In my opinion, myStruct should be bound inside derived , and this code should cause the same error:
#include <iostream> template <typename T> class base { }; struct myStruct; class derived : base<derived::myStruct> { public: struct myStruct { }; }; int main () { return 0; }
Update : gcc-4.5.1 may throw the expected error , so I think the above is an error in VS2010 ...
source share