Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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++11 boost::变量和运算符<&书信电报;超载_C++11_Operator Overloading_Ostream_Boost Variant - Fatal编程技术网

C++11 boost::变量和运算符<&书信电报;超载

C++11 boost::变量和运算符<&书信电报;超载,c++11,operator-overloading,ostream,boost-variant,C++11,Operator Overloading,Ostream,Boost Variant,我想测试一个简单的东西,如下所示: #include <iostream> #include <boost/variant.hpp> template<typename T1,typename T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1,T2>& dt){ os << dt.first <<

我想测试一个简单的东西,如下所示:

#include <iostream>
#include <boost/variant.hpp>

template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1,T2>& dt){
    os << dt.first << dt.second;
    return os;
}



int main(){

   boost::variant<int, std::pair<int,int>, bool> v;
   v = std::pair<int,int>(3,3);
   std::cout << v << std::endl;

}
带有以下信息:

/usr/local/include/boost/variant/detail/variant_io.hpp|64|error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'
/usr/local/include/boost/variant/detail/variant_io.hpp|64|错误:无法将'std::basic_ostream'左值绑定到'std::basic_ostream&'
有人知道我做错了什么,为什么吗?


非常感谢

最有可能的是,它没有发现您的
操作符的重载重载
操作符,而这不是我们需要知道的能够诊断问题的地方。当模板定义出现问题时,编译器将打印一个扩展链。我们需要完整的输出来告诉您发生了什么。由于错误消息似乎来自MSC++,我要提到的是,您需要从Visual Studio中的“输出”选项卡获取消息,“错误”窗口已过滤掉注释,因此没有用。注意事项立即跟随错误消息。思考…思考…思考。。。这次的答案其实很简单。但这并不是草率提问的借口;无论何时询问编译问题,完整的编译器输出都是必需的。对不起,这个转储问题:我为上面的问题添加了解决方案,正如其他帖子中提到的那样below@Gabriel请不要编辑您的问题以让其他人知道问题已解决。将答案标记为已接受。有一条规则规定,您不得在
std
命名空间中放入任何内容,除非为用户定义的类型重载其符号。
/usr/local/include/boost/variant/detail/variant_io.hpp|64|error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'