list with different class objects

Discussion in 'C++' started by Johan, Jan 28, 2004.

  1. Johan

    Johan Guest

    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
     
    Johan, Jan 28, 2004
    #1
    1. Advertising

  2. "Johan" <> wrote...
    > 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
     
    Victor Bazarov, Jan 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,786
    Thomas Weidenfeller
    Oct 12, 2005
  2. roopa
    Replies:
    6
    Views:
    751
    Jerry Coffin
    Aug 27, 2004
  3. 7stud
    Replies:
    11
    Views:
    699
    Dennis Lee Bieber
    Mar 20, 2007
  4. pradeep
    Replies:
    3
    Views:
    809
    cwdjrxyz
    Jun 7, 2007
  5. Nico Grubert
    Replies:
    1
    Views:
    331
    Peter Otten
    Jan 10, 2008
Loading...

Share This Page