Bug 21644 - protected members of templated base class not accessible in derived class
Summary: protected members of templated base class not accessible in derived class
Status: RESOLVED DUPLICATE of bug 15552
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-18 12:36 UTC by Frank Schmitt
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Schmitt 2005-05-18 12:36:24 UTC
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++.
Comment 1 Frank Schmitt 2005-05-18 12:37:37 UTC

*** This bug has been marked as a duplicate of 15552 ***