本文介绍了不能创建一个带有空元组的一元元组(c ++ 0x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在尝试元组,遇到创建元组的问题。 代码示例如下。 // a.cpp #include< tuple> using namespace std; int main(){ auto te = make_tuple(); // this line is ok auto tte = make_tuple(te); //此行给出错误。 return 0; } 我使用g ++ 4.5(g ++ -std = c ++ 0x a.cpp)和MS VC ++ 2010。 两个编译器都在main()的第二行给我一个错误。 我的问题是:因为'te'良好定义的变量,为什么不能创建te是内容的另一个元组。这个语义是否正确? 我猜这是一种边界情况,但如果算术正确,应该允许零。 $ b FYI,来自gcc的错误消息是: $ gcc -std = c ++ 0x a.cpp 在a.cpp中包含的文件中:1:0:c:\mingw\bin\ ../ lib / gcc / mingw32 / 4.5.2 / include / c ++ / tuple:in constructor 'std :: tuple< _Elements> :: tuple(std :: tuple< _UElements ...>&)[with _UElements = {}, _Elements = {std :: tuple<>}]': c:\mingw\bin\../lib/gcc/mingw32/ 4.5.2 / include / c ++ / tuple:551 :62:从实例化std :: tuple< typename std :: __ decay_and_strip< _Elements> :: __ type ...> std :: make_tuple(_Elements&& ...)[with _Elements = {std :: tuple<>&},typename std :: __ decay_and_strip< _Elements> :: __ type =< ; type error>]' a.cpp:6:27:从这里实例化 c:\mingw\bin\ ../ lib / gcc / mingw32 / 4.5.2 / tuple<>'到类型'const std :: _ Tuple_impl< 0u>&' 上的/ include / c ++ / tuple:259:70:error:invalid static_cast code> 解决方案这看起来像是编译器匹配你的 std ::对于 std :: tuple< std :: tuple<>> 的以下构造函数使用元组<> (见20.4.2p15-17在N3242中):I think this is a bug in the implementation of std::tuple from your compiler; the "remark" implies that this constructor should not be considered, since it won't compile. 这篇关于不能创建一个带有空元组的一元元组(c ++ 0x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 04:33