list with different class objects

J

Johan

Hi,

How to create a list with template classes. I want to do something like this

template<class T>class Callback
{
// rest of class
};

typedef list< template<class T>Callback<T> *> CallbackList;

Later
class A
{
public :
void addCallback( ????? );
// rest of class
CallbackList cl;
};

void A :: addCallback( ???? )
{
cl.push_back< ????? >
}

How to add diffenrent class object to the linked list and what to change for
????

thanks

Johan
 
V

Victor Bazarov

Johan said:
How to create a list with template classes. I want to do something like this

template<class T>class Callback
{
// rest of class
};

typedef list< template<class T>Callback<T> *> CallbackList;

There is no template typedefs. You can only have a typedef of
a particular class/type. You need 'T' defined here.
Later
class A
{
public :
void addCallback( ????? );
// rest of class
CallbackList cl;

You cannot have an object of an incomplete type (even if you
could have template typedefs). You would still need to define
the "T" in your 'CallbackList'.
};

void A :: addCallback( ???? )
{
cl.push_back< ????? >
}

How to add diffenrent class object to the linked list and what to change for
????

Look up "heterogeneous containers" on Google. And if you don't see
it, the very first question you need to ask yourself is "why am I
putting those _unrelated_ objects in the same container?" Perhaps
it will give you the idea to make them related somehow...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top