Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Oriented Programming doubt

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
i have two classes (for example X and Y) and i need a method in each one which let me obtain an object from the other class. I´ve tested the next:

file x.hpp------------------
#include "y.hpp"
class X
{
...
public:
void &toY(Y &y)
{
y.function(...)
...
}
...
}
end of file x.hpp------------------

file y.hpp------------------
#include "x.hpp"
class Y
{
...
public:
void &toX(X &x) {...}
void function() {...}
...
}
end of file y.hpp------------------

file main.cpp------------------
#include "x.hpp"
#include "y.hpp"
main()
{
X ox;
Y oy;

ox.toY(oy); //ox change to oy
...
}
end of file main.cpp------------------


but in each file i´m including the class (file) that i want to get, so i get the compiling error:

"...'y' uses undefined class 'X'"

How can i make this work?

Thank you
bye
 
Prototype the classes. In X.hpp, before the line "class X {", write

class Y;

And do the same in Y.hpp for class X.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top