The following code doesn’t compile with gcc, but does with Visual Studio:
template <typename T> class A { public: T foo; }; template <typename T> class B: public A <T> { public: void bar() { cout << foo << endl; } };
I get the error:
test.cpp: In member function ‘void B::bar()’:
test.cpp:11: error: ‘foo’ was not declared in this scope
But it should be! If I change bar to
void bar() { cout << this->foo << endl; }
then it does compile, but I don’t think I have to do this. Is there something in the official specs of C++ that GCC is following here, or is it just a quirk?
This changed in gcc-3.4. The C++ parser got much more strict in that release — per the spec but still kinda annoying for people with legacy or multi-platform code bases.