I am trying to access a protected member variable of a base class template from within the derived class template. My compiler (g++ 4.1.2) complains however:
Why is this considered an error?test.cc: In member function ‘int Derived<T>::protectedVariable() const’:
test.cc:14: error: ‘protectedVariable_’ was not declared in this scope
I have browsed through the C++ standard and sofar I have only found confirmation that this code should compile for non-template classes (which indeed it does). As far as templates go however, I did not find anything that could shed light on this error. Did I overlook something?
Sample code (test.cc) attached.
Code:template <class T> class Base { protected: int protectedVariable_; }; template <class T> class Derived: public Base<T> { public: int protectedVariable() const { return protectedVariable_; } }; int main() { Derived<int> derived; int var = derived.protectedVariable(); return 0; }



LinkBack URL
About LinkBacks




CornedBee