C++ 没有命名空间std的友元重载运算符
只是想知道是否有人能给我指出正确的方向。我有一个friend extraction操作符,如果我包含名称空间std,它就可以工作;但如果我不这样做,就失败了。谁能给我一个提示吗C++ 没有命名空间std的友元重载运算符,c++,namespaces,std,friend,extraction,C++,Namespaces,Std,Friend,Extraction,只是想知道是否有人能给我指出正确的方向。我有一个friend extraction操作符,如果我包含名称空间std,它就可以工作;但如果我不这样做,就失败了。谁能给我一个提示吗 ostream& operator << (ostream &out, coins &value) ostream&operator存在于std名称空间中的是ostream,不要std::是否包含?这不是提取运算符:这是插入运算符。这是一个有趣的问题。根据here(),非ostrea
ostream& operator << (ostream &out, coins &value)
ostream&operator存在于std
名称空间中的是ostream
,不要std::是否包含
?这不是提取运算符:这是插入运算符。这是一个有趣的问题。根据here(),非ostream成员重载在名称空间std中定义;如果不使用名称空间std,编译器如何通过@h9uest:Argument dependent lookup知道。
#include <iostream>
struct coins
{
friend std::ostream& operator<<(std::ostream& sink, const coins& value);
};
std::ostream& operator<<(std::ostream& sink, const coins& value)
{
sink << "doing coins output";
return sink;
}
int main()
{
coins c;
std::cout << c << std::endl;
}