This should compile but doesn't in g++ 3.4.2 (it works in 3.3): template<typename T> class Base { protected: T m_member; }; template<typename T> class Derived : public Base<T> { public: Derived(T val) { m_member = val; } };
test.cpp:11: error: `m_member' undeclared (first use this function) The workaround is to add an explicit qualifier: Derived(T val) { Base<T>::m_member = val; } A similar issue arises with protected methods, with a different error message: template<typename T> class Base { protected: BaseMethod() { } }; template<typename T> class Derived : public Base<T> { public: Derived(T val) { BaseMethod(); } }; test.cpp:5: error: ISO C++ forbids declaration of `BaseMethod' with no type test.cpp: In constructor `Derived<T>::Derived(T)': test.cpp:11: error: there are no arguments to `BaseMethod' that depend on a template parameter, so a declaration of `BaseMethod' must be available -- Summary: Protected members inaccessable in templated derived class Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mleone at pixar dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: Red Hat 3.4.2-6.fc3 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21500