Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,397 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,106 people online right now. Registration is fast and FREE... Join Now!




in complete type

 
Reply to this topicStart new topic

in complete type, in complete type

srishekh
29 Sep, 2006 - 03:02 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2006
Posts: 10


My Contributions
Dear Sir/Madam

I am using a c++ file with class names, namely A and B. And I want an object of type class A in class B, and an object of type class B in class A.

When I compile the program it gives in complete type error. I want this design in my project.
Sir, how to come arround this problem.
Please tell me.
Code is shown below.
CODE

#include <iostream.h>
class B;
class A
{
private:B ob1;
public :
void set(B ob)
{
ob1 = ob;
}
};

class B
{
private:A ob1;
public : void set(A ob)
{
ob1 = ob;
}
};


int main()
{
A x;
B y;
x.set(y);
return 0;
}

User is offlineProfile CardPM
+Quote Post

born2c0de
RE: In Complete Type
29 Sep, 2006 - 09:57 AM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,935



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
CODE

void set(B ob)
{
ob1 = ob;
}

You can't use the assignment operator for objects like how you do for variables.

You'll need to overload the = operator and explicitly copy the contents of the object into the other.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:57AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month