usage of undefined class

Discussion in 'C++' started by =?ISO-8859-1?Q?Kristoffer_M=F6gle?=, Dec 10, 2003.

  1. Hello,

    I would like to define a class (ListA) which can store elements of
    another class (A). The problem is, that I want to use this class (ListA)
    inside class A. (See code below.)
    Of course I could use void* instead of A* in ListA but I would prefer a
    way where do not always have to cast my pointers.
    Is there a possibility to realize it (kind of) this way?

    Thanks in advance!
    Kris



    class ListA {
    private:
    A * head;
    public:
    bool Add ( A * );
    A * operator [] ( unsigned int );
    ...
    };

    class A {
    public:
    ListA * foo;
    ...
    };
     
    =?ISO-8859-1?Q?Kristoffer_M=F6gle?=, Dec 10, 2003
    #1
    1. Advertising

  2. "Kristoffer Mögle" <-chemnitz.de> a écrit dans le message de
    news: br7674$tpm$-chemnitz.de...
    > Hello,
    >
    > I would like to define a class (ListA) which can store elements of
    > another class (A). The problem is, that I want to use this class (ListA)
    > inside class A. (See code below.)
    > Of course I could use void* instead of A* in ListA but I would prefer a
    > way where do not always have to cast my pointers.
    > Is there a possibility to realize it (kind of) this way?
    >
    > Thanks in advance!
    > Kris
    >
    >
    >
    > class ListA {
    > private:
    > A * head;
    > public:
    > bool Add ( A * );
    > A * operator [] ( unsigned int );
    > ...
    > };
    >
    > class A {
    > public:
    > ListA * foo;
    > ...
    > };




    try this :

    class A;

    class ListA;

    class ListA

    {

    A *m_pA;

    };

    class A

    {

    ListA *m_pListA;

    };

    should compile fine.
     
    Le Géant Vert, Dec 10, 2003
    #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,782
    Thomas Weidenfeller
    Oct 12, 2005
  2. Alex Vinokur
    Replies:
    1
    Views:
    448
    Alf P. Steinbach
    Sep 27, 2004
  3. Mantorok Redgormor
    Replies:
    70
    Views:
    1,763
    Dan Pop
    Feb 17, 2004
  4. VK
    Replies:
    45
    Views:
    602
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    373
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page