J
Jeff Perry
When I try to compile the code below with gcc 3.4.1, I get an error.
In order to get the code to compile, I have to specify i's scope by
prepending 'B::' to 'i' in function D::F(). Can someone tell me why
this is true?
The non-template version of this class hierarchy works without the
scope specifier on 'i'.
template<typename T>
class B {
public:
virtual void F () { }
T i;
};
template<typename T>
class D: public B<T> {
public:
virtual void F () { i = 1; } // error: 'i' undeclared
// but 'B::i = 1;' works
};
int main ()
{
D<unsigned> d;
d.F ();
return 0;
}
In order to get the code to compile, I have to specify i's scope by
prepending 'B::' to 'i' in function D::F(). Can someone tell me why
this is true?
The non-template version of this class hierarchy works without the
scope specifier on 'i'.
template<typename T>
class B {
public:
virtual void F () { }
T i;
};
template<typename T>
class D: public B<T> {
public:
virtual void F () { i = 1; } // error: 'i' undeclared
// but 'B::i = 1;' works
};
int main ()
{
D<unsigned> d;
d.F ();
return 0;
}