Possible Duplicate:
Base template class data members are not visible in derived template class?
I am trying to create a templated class that extends a templated super-class.
template <class T>
class SuperClass {
public:
T my_data;
};
template <typename T2>
class SubClass : public SuperClass<T2>
{
public:
T2 f() { return my_data; }
};
int main()
{
SubClass<int> x;
return 0;
}
However, I get the following error (using g++ 4.6.1):
test.cpp:11:18: error: ‘my_data’ was not declared in this scope
Strangely, it works if I redefine SubClass::f()
as follows:
T2 f() { return this->my_data; }
Does anyone understand why I need to have a this->
?