我在A類定義< <操作是這樣的: 啊:不能綁定 '的std :: basic_ostream' 左值到 '的std :: basic_ostream <char> &&'
class API_name A {
friend API_name std::ostream& operator<<(std::ostream& o, const A&a);
}
A.cpp:
ostream& operator<<(ostream& o, const A& a);
在另一個文件中,包括嗯,我想這樣做:
void fonction(const A* a) {
std::cout << "a contains : " << *a << std::endl;
}
在這條線,我的gcc返回以下錯誤:
錯誤:無法綁定「的std :: basic_ostream」左值到「的std :: basic_ostream & &」
有人能告訴我爲什麼,以及如何避免這個編譯錯誤?
的和在定義mentionned。我在寫這個問題時犯了一個輸入錯誤,並且我收到了這個編譯錯誤。 – FlashMcQueen
@FlashMcQueen:那麼問題不在於您發佈的代碼中,至少就我們所見。您可能需要發佈[mcve]。例如,什麼是「API_name」,以及你的類和函數是如何安排在名稱空間中的? – AndyG
好的,我會這樣做的。 – FlashMcQueen