C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template inheritance

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
zl2k
Guest





PostPosted: Thu Aug 17, 2006 9:01 am    Post subject: template inheritance Reply with quote



hi, all
Suppose I have a template class A

template<class T> class A{...}

Then I have another class B which inherits class A. Should I say

class B: public A{...}

or class B: template<class T> A{...}

or template<class T> class B : public A {...}

or something else? I assume that class A is also a template. But can
class A be a non template class? If yes, how can A handle the different
type of T? Thanks ahead.

zl2k
Back to top
Frederick Gotham
Guest





PostPosted: Thu Aug 17, 2006 9:05 am    Post subject: Re: template inheritance Reply with quote



template<class T>
class Derived : public Base<T> {

};

--

Frederick Gotham
Back to top
Thomas J. Gritzan
Guest





PostPosted: Thu Aug 17, 2006 9:10 am    Post subject: Re: template inheritance Reply with quote



zl2k schrieb:
Quote:
hi, all
Suppose I have a template class A

template<class T> class A{...}

Then I have another class B which inherits class A. Should I say

class B: public A{...}

or class B: template<class T> A{...}

or template<class T> class B : public A {...}

Depends.

If you want class B to be a template like class A, then:

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

If you want that class B inherits from a specific class A, say with
template parameter int:

class B : public A<int>
{
// ...
};

--
Thomas
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.