在我的条目cpp文件中,以下工作。
include <vector>
#define ROWS 10
#define COLS 20
std::vector<std::vector<int>> exampleVector (ROWS, std::vector<int>(COLS, 10));
但是,如果我将相同的代码放在我的example.h文件中,我会得到
我知道我可以放
std::vector<std::vector<int> exampleVector;
在我的example.h文件和
中exampleVector.resize(ROWS, std::vector<int>(COLS, 10));
在我的example.cpp文件中。
但是为了清洁代码,我希望在我的头文件中加上我的固定数组。
char exampleName[MAX_NAME_LENGTH]
int exampleConfig[MAX_LEVELS]
等
答案 0 :(得分:-2)
您的示例代码出现了问题(关闭>
?)但忽略了这一点,答案是:在定义时无法指定std::vector
的大小
另一方面,std::array
的大小可以是:
#include <array>
#define ROWS 10
#define COLS 20
std::array<std::array<int, ROWS>, COLS> exampleArray;