Given the below classes are in two separate header files and can appear in any order:
//TestB.h
class TestB; //Forward declaration for a later operator= in a centralised header
class TestA
{
const TestA&operator=(const TestB); //defined in Test.h
};
And:
//TestA.h
class TestA; //Forward declaration for a later operator= in a centralised heaer
class TestB
{
const TestB&operator=(const TestA); //defined in Test.h
};
How do I avoid the prototype conflict?
Help is appreciated.
I absolutely apologise to everyone! I had intended for there to be references (ampersands in the operator= arguments – I would never pass by copying bar simple PODs) and meant the question solely about prototyping conflicts! I guess it goes to show the importance of proof-reading! I have accepted the answer given the original (my erroneous) context.
I had merely only turned away for a few minutes and was not aware of the fault!
You pass references to the classes as parameters. This way, a class and its member functions can be declared without knowing about the other.
And:
After this, you’ll have to include both TestA.h and TestB.h in both TestA.cpp and TestB.cpp files to be able to define these member functions.