c++二维向量语法错误
c++ two dimensional vector syntax error
有一个common.h文件:
typedef enum {
num_letters = 26,
num_directions = 2
} constants;
和另一个类的。h文件:
#include "Common.h"
using namespace common;
... some code ...
vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));
我检查了向量的语法,它应该是正确的;我也在使用c++11 std;然而,它给了我以下错误:
error: 'constants::num_directions' is not a type
vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));
error: expected unqualified-id before ',' token
vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));
^
error: expected ')' before ',' token
error: expected ')' before ',' token
error: expected unqualified-id before numeric constant
vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));
,我真的不知道为什么会发生,非常感谢你提前!
您没有提供足够的代码来可靠地重现您的问题,因此我将大胆猜测:
从编译器发出的错误消息来看,它似乎将整行解释为函数声明而不是变量定义。这可能是由于这样一个事实,正如在评论中指出的那样,constants::num_directions
不是使用普通enum的枚举数的有效方式。所以编译器会像解析函数声明那样解析这一行
ResultType f(ArgType1, Argtype2(argname2))
ResultTyoe是vector<vector<uint>>
, ArgType1
是constants::num_directions
,它不识别为类型,ArgType2
是vector<uint>
,然后它完全丢失了,因为它不能使头部或尾部的其余部分。
相关文章:
- 很好的语法来获取对向量/数组数据的大小引用?
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- priority_queue使用降序向量实现最小堆的语法差异
- 转换包含向量 C++ 的语法和结构
- 为什么具有两个元素的发起器语法将一个元素而不是两个元素放入字符串向量中?
- 如何创建一个function_list<>类来保存具有相同模板语法的 std::function<>s 向量?
- 如何使用 c++11 语法创建 for 循环以遍历向量
- 向量特定语法的向量
- C++中各种向量突变方法的语法
- 非标准语法;使用 '&' 创建指向成员的指针错误,将成员函数分配给向量时出错
- (C++)用于实例化新对象并将其分配给指向相同对象类型的指针的 2D 向量的语法
- 适当的语法用于在类内使用向量
- C++返回不可变指针向量的函数语法
- 在 VS12 中将初始值设定项列表作为向量的函数参数传递时出现语法错误
- 向量的 C# memcpy 等效项 (C# 列表) <T>(语法糖)
- c++二维向量语法错误
- 指针的向量,推入元素的语法
- 如何在c++ 11语法中初始化向量的向量
- 向量从R到c++的语法是什么?
- Boost Spirit语法用于识别从一行到向量的一系列数字