This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/21644] New: protected members of templated base class not accessible in derived class
- From: "tonne2005 at gehheimdienst dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 May 2005 12:36:26 -0000
- Subject: [Bug c++/21644] New: protected members of templated base class not accessible in derived class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
See the following code example:
#include <iostream>
template <typename tn>
class a{
protected:
tn bar;
public:
a(tn bar){
this->bar=bar;
}
virtual tn getBar(){
return bar;
}
};
template <typename tn>
class b : public a<tn>{
private:
void add(tn baz);
public:
b(tn bar, tn baz)
: a<tn>(bar)
{
add(baz);
}
};
template <typename tn>
void b<tn>::add(tn baz){
bar+=baz;
}
int main(){
b<unsigned> test(7,5);
std::cout << test.getBar() << std::endl;
return 0;
}
This gives
test.cpp: In member function `void b<tn>::add(tn)':
test.cpp:30: error: `bar' undeclared (first use this function)
test.cpp:30: error: (Each undeclared identifier is reported only once for each
function it appears in.)
As well as it's (in my and the opinion of ##c++) valid ANSI C++.
--
Summary: protected members of templated base class not accessible
in derived class
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tonne2005 at gehheimdienst dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21644