如果我有一个带有重载流运算符的POD:
这给了我:
struct Value{
...
friend ostream& operator<< (ostream &out, Value &val);
...
};
我无法使用流运算符处理匿名实例。 例如,我不能这样做:
cout<<Value();
这给了我:
error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘Value’)
另一方面,我可以按值传递POD,但我想避免复制。有没有办法两者兼顾?
Value v1;
cout<<v1<<" "<<Value()<<endl;