For example, I have 2 classes as defined in following order…
class A
{
int value;
printValue(B b)
{
cout << b.value
}
};
class B
{
int value;
printValue(A a)
{
cout << a.value;
}
}
How can I use the B object in A, as B definition is below ?
You can separate declaration and implementation of the classes, forward declare them in the declaration header files, and use references in the functions.
file A.h
file B.h
Then, have separate implementation files. For example,
A‘s implementation fileA.cpp:and similarly for
B.cpp.Note that I have fixed the missing return types for the
printValuefunctions, and made those functionsconst.