Domanda

Ho la mia classe per esempio In Test.h ho

Amico Ostream & Operator << (ostream e out, Const Test & Outstr);

in test.cc

Ostream & Operator << (OSTREAM e OUT, TEST & STOUT) { fuori << "test"; ritorno; }

in Main test x; cout << x;

Io ricevo il messaggio di errore: Errore: riferimento indefinito a `operatore << (std :: basic_ostream> &, test const &)

Qual è il problema?

È stato utile?

Soluzione

Hai const nella Dichiarazione:

Amico Östream & Operator << (Ostro e uscita, Const Test & OUTSTR);

e senza const nell'implementazione:

Ostream & Operator << (Ostream e OUT, Missing Const Test & Sgout)

L'aggiunta di Const all'attuazione dovrebbe risolvere il tuo problema.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top