C ++ Class Prototype Conflict

Given that the classes below are in two separate header files and can be displayed 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 to avoid prototype conflict?

Help is appreciated.

I absolutely apologize to everyone! I assumed that there would be links (ampersands in the operator = arguments - I would never go through copying simple PODs) and had in mind the question exclusively about prototyping conflicts! I think this speaks of the importance of evidence! I accepted the answer, given the original (my erroneous) context.

I just turned away for just a few minutes and did not know about the wine!

+5
source share
4 answers

. , - .

//TestB.h
class TestB; //Forward declaration for a later operator= in a centralised header

class TestA
{
    const TestA&operator=(const TestB &); //defined in TestB.h
};

//TestA.h
class TestA; //Forward declaration for a later operator= in a centralised heaer

class TestB
{
    const TestB&operator=(const TestA *); //defined in TestA.h
};

TestA.h, TestB.h TestA.cpp TestB.cpp, -.

+4

.

, , . :

// A.cpp
#include "A.h"
#include "B.h"  // for complete type TestB

const TestA & TestA::operator=(const TestB) { /* ... */ }

// B.cpp
#include "B.h"
#include "A.h"  // for complete type TestA

const TestB & TestB::operator=(const TestA) { /* ... */ }

, , TestA TestB, , A.h, B.h, , . , , , ( !) .


< > , , .

, , , :

const TestA & operator=(const TestB &);
                                  ^^^^^
                                  vvvvv
const TestB & operator=(const TestA &);

+4

, - . , - .cpp, - , .

, -, , , - , , .

, , .

+1

... , . , , , , (.. ) ..), , .

0

All Articles