Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 没有命名空间std的友元重载运算符_C++_Namespaces_Std_Friend_Extraction - Fatal编程技术网

C++ 没有命名空间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

只是想知道是否有人能给我指出正确的方向。我有一个friend extraction操作符,如果我包含名称空间std,它就可以工作;但如果我不这样做,就失败了。谁能给我一个提示吗

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;
}