#include <iostream>
using namespace std;
struct OutputStream
{
template<class T>
OutputStream& operator <<(const T& obj)
{
cout << obj;
return *this;
}
};
OutputStream os;
int main()
{
os << 3.14159 << endl; // Compilation Failure!
}
VC++ 2012 编译器抱怨:
错误 C2676:二进制“<<”:“OutputStream”未定义此运算符或转换为预定义运算符可接受的类型