我试图超载运算符< <。我期待的输出是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
如果编译器无法确定,他会得到一个编译器错误。编译器不会随机选择一个... –