|
-
Dec 11th, 2003, 01:23 PM
#1
Thread Starter
Frenzied Member
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
Last edited by wey97; Nov 10th, 2004 at 09:59 AM.
-
Dec 11th, 2003, 02:10 PM
#2
Monday Morning Lunatic
How about putting:...above the two definitions?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 11th, 2003, 02:13 PM
#3
Thread Starter
Frenzied Member
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;
};
-
Dec 11th, 2003, 02:33 PM
#4
Thread Starter
Frenzied Member
I guess it could be a circular definition type thing.
-
Dec 12th, 2003, 07:53 AM
#5
transcendental analytic
don't type the definitions inline
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 12th, 2003, 10:37 AM
#6
Member
Hi ,
U need forward declaration of the class cl2.
Just write "class cl2" before class cl1 declaration.
Try it..
-
Dec 13th, 2003, 10:12 AM
#7
Wrong avaneesh, that won't suffice.
What keda said. Put the implementations of cl1's methods after the definition of cl2.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|