【发布时间】:2013-01-21 01:00:38
【问题描述】:
可能重复:
std::endl is of unknown type when overloading operator<<
#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:二进制 '
【问题讨论】:
-
你没有定义 endl
-
T不适用于endl吗?
-
我认为它会适用,但代码确实在没有 endl 的情况下编译。我就等大佬回答了。 :p
-
好吧,因为它是完全重复的......删除这个?
-
我已投票关闭我的这篇文章。
标签: c++ class stream iostream template-function