468,513 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

inherit template class

4
i want to inhert atemplate class
example:
template<class t>
class list
{
protected:
t data;
list* nextptr;
public:
void push()=0;
void pop()=0;
}
now i want to make a new class called stack and this class inherit the list public
is this true?
class stack:public list
{
.........
}
int main()
{
also in main when i create object of stack what i do?
stack<int> ob;
is this true?

please any one help me
Sep 8 '06 #1
2 5974
Banfa
9,056 Expert Mod 8TB
I think everything you have done is correct given the level of detail supplied by yourself.
Sep 8 '06 #2
vermarajeev
180 100+
Try out something like this

Expand|Select|Wrap|Line Numbers
  1. template<class T>
  2. class Base
  3. {
  4. public:
  5.     Base(){}
  6.     ~Base(){}
  7.     virtual void func();
  8. };
  9. template<class T>
  10. void Base<T>::func()
  11. {
  12.     cout<<"My Base func"<<endl;
  13. }
  14.  
  15. template<class T>
  16. class Derived:public Base<T>
  17. {
  18. public:    
  19.     Derived()
  20.     {}
  21.     ~Derived(){}
  22.     void func();    
  23. };
  24.  
  25. template<class T>
  26. void Derived<T>::func()
  27. {
  28.     cout<<"My Derived func"<<endl;
  29. }
  30.  
  31. template<class T>
  32. void userFun(T* b)
  33. {
  34.     b->func();
  35. }
  36. int main(int argc, char* argv[])
  37. {
  38.     Base<int> *b;
  39.     Derived<int> d;
  40.     b = &d;
  41.     userFun(b);
  42.     return 0;
  43. }
Update me, if anything wrong???
Sep 9 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jill Graham | last post: by
1 post views Thread by JKop | last post: by
3 posts views Thread by Jill Graham | last post: by
3 posts views Thread by cagenix | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.