This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/21500] New: Protected members inaccessable in templated derived class
- From: "mleone at pixar dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 May 2005 18:32:18 -0000
- Subject: [Bug c++/21500] New: Protected members inaccessable in templated derived class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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