473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to have different child classes of a template base class in a container?

I have a template class called Base with child classes called Child1
and Child2 as follows:

template <typename T>
class Base
{

};

class Child1 : Base<Concrete1>
{

};

class Child2 : Base<Concrete2>
{

};

Concrete1 and Concrete2 classes are derived from a class called
ConcreteBase.

Now I need to create a list containing both Child1 and Child2 but the
following doesn't work.

std::list<Base<ConcreteBase> *> BaseList;

How can I create the above list?

Thanks for your replies.

Vikas
Jul 19 '05 #1
1 2057
"Vikas" <vs*****@hotmail.com> wrote...
I have a template class called Base with child classes called Child1
and Child2 as follows:

template <typename T>
class Base
{
.
};

class Child1 : Base<Concrete1>
{
.
};

class Child2 : Base<Concrete2>
{
.
};

Concrete1 and Concrete2 classes are derived from a class called
ConcreteBase.

Now I need to create a list containing both Child1 and Child2 but the
following doesn't work.

std::list<Base<ConcreteBase> *> BaseList;

How can I create the above list?


You cannot. Your only option is

class BaseOfBases {
...
};

template<class T>
class Base : public BaseOfBases {
...
};

std::list<BaseOfBases*> BaseList;

Victor
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
10
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
4
by: lizhuo | last post by:
hi all: I reading "C++ Templates: The Complete Guide " Part II: Templates in Depth 9.4.1 Nondependent Base Classes he write$B!'(B In a class template, a nondependent base class is one with a...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
13
by: bob the builder | last post by:
Can i get the class of an object of which i only have the address? Lets say i have 3 classes: AClass,BClass,CClass. i also have an object of each class: aObject, bObject, cObject And finally i...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.