元组列表c++ 11/1y
C++: List of tuples C++11/1y
前面的一个问答(这里)表明,可以通过以下方式创建一个元组列表:
#include <vector>
#include <boost/tuple/tuple.hpp>
using namespace std;
using boost::tuple;
typedef vector< tuple<int, int> > tuple_list;
当我在c++ 98运行时没有得到错误,c++ 1y (Ubuntu上的GCC/GNU)给出:
error: template argument 1 is invalid
typedef vector< tuple<int, int> > tuple_list;
^
error: template argument 2 is invalid
error: invalid type in declaration before ‘;’ token
typedef vector< tuple<int, int> > tuple_list;
^
知道是怎么回事吗?(如果我能在其他帖子上发表评论,我会的,但是awesome SO说我的声誉太低了,不能发表评论!)
问题是名称冲突,您是using boost::tuple
和namespace std;
,两者都将tuple
带入全局作用域,因此您最终得到同一模板的两个定义。我不明白为什么编译器在诊断错误时不更明确…
删除using boost::tuple;
或using namespace std;
并限定相应的名称:
#include <vector>
#include <boost/tuple/tuple.hpp>
//using namespace std;
//using boost::tuple;
typedef std::vector< boost::tuple<int, int> > tuple_list;
int main()
{
tuple_list foo;
}
我想这是一个很好的例子,为什么using
不太推荐;)
相关文章:
- 如何让 CMake 基于 GCC 版本通过 std=c++14/c++1y 或 c++17/c++1z?
- 这种递归多态 C++1y lambda 调用有什么问题?
- 提升范围不适用于 C++1y 初始化捕获可变 lambda
- 什么是c++11/1y lambda函数的类型签名
- 范围/切片以 C++11/1y 为单位
- 我们可以使用C 1y std :: tie()类似功能进行深入领带吗?
- -O1/2/3 与 -std=c++1y/11/98 - 如果包含,<cmath>我收到错误:"_hypot"未在此范围内声明
- 在qt(mingw)中启用c++1y
- 类方法的返回类型推导?C++1y.
- 在 C++11 或 C++1y 中对非类型模板参数包进行排序
- C++1y/C++14:变量模板专用化
- 在 C++1y 中是必需的公共类类型定义
- 理解建议N3650中C++1y的可恢复函数示例
- 使用std::move在unique_ptr上对c++ 1y中模板化基类派生的类型进行操作
- 如何在c++1y中保留cv限定符或返回类型推导中的引用
- C++14/1y: "operator+ must take either one or two arguments"的标准参考 ?
- 'constexpr'非静态成员函数不会隐式'const'在 C++1y 中;添加'const'以避免行为更改
- 为什么在 C++1y 中没有接口来获取 std 文件系统库扩展中的用户/组信息
- 元组列表c++ 11/1y
- c++ 1y/14:自动变量模板