473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

inherit template class

4 New Member
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 6423
Banfa
9,065 Recognized Expert Moderator Expert
I think everything you have done is correct given the level of detail supplied by yourself.
Sep 8 '06 #2
vermarajeev
180 New Member
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

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

Similar topics

0
by: Jill Graham | last post by:
Hi folks, The pages of my website are built dynamically and are based on templates. A template can look like this : <table> <tr><td>This is the page header</td></tr> <tr><td>This is the...
1
by: JKop | last post by:
First attempt: class Blah : public int { }; So I began working on the next best thing:
6
by: blah | last post by:
Hi, Is it possible to force the typename of a template to inherit from a particular class? For example, something like this (conceptual; this doesn't compile): class Parent { public: ...
3
by: Jill Graham | last post by:
Hi folks, The pages of my website are built dynamically and are based on templates. A template can look like this : <table> <tr><td>This is the page header</td></tr> <tr><td>This is the...
3
by: Allerdyce.John | last post by:
I would like to know what is the advantage of inherit from unary_function template? For example, I have this in my code: What is the advantage of doing this: class Same :...
3
by: cagenix | last post by:
I was running through a data structures book and I was curious if anyone could inform me of how to inherit the vector class to do a simple search and erase function. The example states: ...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
3
by: Clownboat | last post by:
I've just written a CSS/HTML flyout menu as an addition to an existing system (EQdkp Plus, to be specific). The menu is generated by a couple PHP functions. The output is an unordered list as in...
5
by: Ashlewis | last post by:
Hi all, I have two aspx pages: Default.aspx with its code behind page of Default.aspx.vb Home.aspx with its code behind page of Home.aspx.vb The Default page in effect is just a template, the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.