inheritance with templates trouble

R

richard

Sorry if this is an obvious question, but I try to let a template class
inherit another template class.

The code here under is a simplification of how I try to do that, but
the compiler complains that 'c' in line '30 ' wasn't declared.

" (g++)
test.h: In member function ‘T Test2<T>::give()’:
test.h:30: error: ‘c’ was not declared in this scope
"

I have absolute no idea what the problem and/or solution is, can anybody
help me with that please?

Thank you,
Driehoek


////////////////////////////////////////
4: template <class T>
5: class Test
6: {
7: public:
8: virtual void
9: set (T i)
10: {
11: c = i;
12:
13: }
14: virtual T
15: give ()
16: {
17: return c;
18: }
19: protected:
20: T c;
21: };
22:
23: template <class T>
24: class Test2 : public Test<T>
25: {
26: public:
27: T
28: give ()
29: {
30: return c * 2;
31: }
32: };
////////////////////////////////////////
 
R

richard

On Fri, 08 Aug 2008 12:55:21 +0000, richard wrote:

Finally I brute forced the solution :), I had to change line 30 to:

////
return Test<T>::c * 2;
////

But I don't really see the logic in this, why do you need to specify the
base class?

Thanks.
 
R

richard

On Fri, 08 Aug 2008 09:41:59 -0400, Victor Bazarov wrote:

Thank you, now it makes sense to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top