我正在尝试编写一个程序来设置嵌套结构,然后初始化该结构的数组。它给了我一些奇怪的错误。以下是所有相关代码:
//Structure called Stats for storing initial character stats
struct Stats{
string name;
int level;
int HP;
int STR;
int CON;
int DEX;
int INT;
int WIS;
int CHA;};
//Structure called Growth for storing character growth per level.
struct Growth{
int HPperlvl;
int STRperlvl;
int CONperlvl;
int DEXperlvl;
int INTperlvl;
int WISperlvl;
int CHAperlvl;};
struct Holdstats{
Stats classstats;
Growth classgrowth;};
const int SIZE = 10;
Holdstats classlist[SIZE];
Holdstats charlist[SIZE];
//Define initial classes, to be stored in the Classes structure
classlist[0].classstats = {"Fighter", 1, 18, 10, 10, 10, 10, 10, 10};
classlist[0].classgrowth = {1,1,1,1,1,1,1};
classlist[1].classstats = {"Wizard", 1, 10, 10, 10, 10, 10, 10};
classlist[1].classgrowth = {1,1,1,1,1,1,1}
我的编译器认为,当我键入“classlist[0].classstats”时,我正在尝试初始化大小为 0 的数组。我阅读此内容的方式是尝试访问 classlist 数组的第一个元素。这写对了吗?
如果有人能给我一个简短的例子来说明这样的数组是什么样的,那就太好了。从那里我想把它写成一个向量