我編輯了這個問題的一篇文章,但沒有得到答案。讓編譯器感知<<爲特定類定義
我超負荷< <爲一類,Score
(在score.h中定義),在score.cpp中。
ostream& operator<< (ostream & os, const Score & right)
{
os << right.getPoints() << " " << right.scoreGetName();
return os;
}
(getPoints
獲取的int
屬性,getName
一個string
一個)
我得到了在main()的測試,包含在main.cpp中這個編譯錯誤
binary '<<' : no operator found which takes a right-hand operand of type 'Score' (or there is no acceptable conversion)
怎麼來的編譯器不會'認識到'重載是有效的? (包括正確)
感謝您的時間。
編輯:
按照要求,代碼導致錯誤:
cout << ":::::\n" << jogador.getScore() << endl;
jogador
是Player
對象,其中包含一個Score
之一。 getScore
返回該屬性。
你一定要發佈導致錯誤的代碼 – UncleZeiv 2010-05-13 17:12:45