template < typename T >
class A {
protected:
T n;
};
template < typename T >
class B : public A< T > { // A partial specialization
public:
void func() {
n = 10;
}
};
int main()
{
B< int > obj;
obj.func();
return 0;
}
The problem here is that the compiler does not know anything about 'n' within the function 'func'. Why? This has something to do with the template instantiation. A template class is never instantiated unless there is a particular instantiation object that comes into the picture. So, only when the compiler sees 'B
using A< T >::n;
This statement within class B would resolve the problem.
Its a sea out there!
No comments:
Post a comment
What I want to say is: