usage of undefined class

  • Thread starter =?ISO-8859-1?Q?Kristoffer_M=F6gle?=
  • Start date
?

=?ISO-8859-1?Q?Kristoffer_M=F6gle?=

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;
...
};
 
L

Le Géant Vert

Kristoffer Mögle said:
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.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top