-
friend classes?
How in the hell can you use two classes inside each other in the
same file?
I could have sworn this used to work:
Code:
class cl1
{
public:
int i;
cl1(cl2 c2){i = c2.i;}
friend class cl2;
};
// error: missing ')' before identifier c2
class cl2
{
public:
int i;
cl2(cl1 c1){i = c1.i;}
friend class cl1;
};
// this is fine
-
How about putting:...above the two definitions?
-
error: use of undefined type 'cl2'
Code:
class cl2;
class cl1
{
public:
int i;
cl1(cl2 c2){i = c2.i;}
friend class cl2;
};
class cl2
{
public:
int i;
cl2(cl1 c1){i = c1.i;}
friend class cl1;
};
-
I guess it could be a circular definition type thing.
-
don't type the definitions inline
-
Hi ,
U need forward declaration of the class cl2.
Just write "class cl2" before class cl1 declaration.
Try it..
-
Wrong avaneesh, that won't suffice.
What keda said. Put the implementations of cl1's methods after the definition of cl2.