Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > derivation of a template class

Reply
Thread Tools

derivation of a template class

 
 
maadhuu
Guest
Posts: n/a
 
      05-17-2005
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??

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      05-17-2005
* 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?
 
Reply With Quote
 
 
 
 
maadhuu
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      05-17-2005
* 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
Operator overloading vs. class derivation/inheritance Massimo Soricetti C++ 6 02-02-2006 06:22 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Why is Python not supporting full derivation of built-in file class? Pierre Rouleau Python 2 04-25-2005 01:31 PM
portected access: template derivation vs. class derivation Steven T. Hatton C++ 12 08-20-2004 04:56 AM



Advertisments