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?
question from:
https://stackoverflow.com/questions/11405/gcc-issue-using-a-member-of-a-base-class-that-depends-on-a-template-argument 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…