我試圖超載運算符< <。我期待的輸出是InitializingHello WorldOut,但它只是輸出Hello World。我無法弄清楚我的代碼有什麼問題。謝謝你的幫助。重載I/O運算符C++
#include <iostream>
using namespace std;
ostream &operator << (ostream &out, const char* &s)
{
out << "Initializing" << s << "Out";
return out;
}
void main() {
cout << "Hello World" << endl;
system("Pause");
}
如果是這樣,他會得到鏈接錯誤的情況。對? –
原型不一樣,標準的不是參考。即使它們在相同的地方,他也不會因爲它們位於不同的命名空間而導致鏈接器錯誤;他會得到一個模糊的電話。 – rodrigo
如果編譯器無法確定,他會得到一個編譯器錯誤。編譯器不會隨機選擇一個... –