By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

derivation of a template class

P: n/a
hello,
i want to know whether one can derive from a template class where the
derived class is also a template class....if this is true, then if i have
2 functions say f() in the parent class and g() in the derived class ,
where the function f() is called,then it gives an error ..why??

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* maadhuu:
i want to know whether one can derive from a template class where the
derived class is also a template class....
Yes; what were you thinking of might be in the way?

template< typename T > class A {};
template< typename T > class B: public A<T> {};

if this is true, then if i have
2 functions say f() in the parent class and g() in the derived class ,
where the function f() is called,then it gives an error ..why??


Post the relevant code.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

P: n/a
template<typename T>
class B {
public:
void f() { }
};

template<typename T>
class D : public B<T> {
public:
void g()
{
f(); // compiler gives an error here
}
};
this is the way it works......my question is whether this is allowed at
all i.e. deriving from a template class

Jul 23 '05 #3

P: n/a
* maadhuu:
template<typename T>
class B {
public:
void f() { }
};

template<typename T>
class D : public B<T> {
public:
void g()
{
f(); // compiler gives an error here
}
};
this is the way it works......my question is whether this is allowed at
all i.e. deriving from a template class


Yes.

You just have to inform the compiler that f is an inherited member routine.

One way is to employ a 'using' directive in class D, another way is to
qualify the call with 'this->'.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.