class Dialogue
{
public:
int id;
int trigger;
Question descendants[5]; // Max questions per dialogue
string text;
};
class Question
{
public:
int id;
int descendant;
int ancestor;
string text;
};
当我尝试构建它时,它会对问题后代的位出现以下错误吗?:
错误1错误C2146:语法错误:缺少';'在标识符之前 '后代'c:\ users ** \ documents \ visual studio 2012 \ projects \ game \ game \ dialogue.h 8 1游戏错误2错误C4430: 缺少类型说明符 - 假设为int。注意:C ++不支持 default-int c:\ users ** \ documents \ visual studio 2012 \ projects \ game \ game \ dialogue.h 8 1游戏
答案 0 :(得分:4)
或者您可以转发声明您的课程。当它们彼此依赖时,这很方便:
class Question; class Dialogue;
class Dialogue { public: int id; int trigger; Question descendants[5]; // Max questions per dialogue string text; };
class Question { public: int id; int descendant; int ancestor; string text; };
答案 1 :(得分:2)
您需要切换定义,以便编译器在Question
声明中使用Dialogue
时知道它。
这将编译:
class Question
{
public:
int id;
int descendant;
int ancestor;
string text;
};
class Dialogue
{
public:
int id;
int trigger;
Question descendants[5]; // Max questions per dialogue
string text;
};
答案 2 :(得分:1)
类问题的定义应首先进行,然后是对话类。
class Question
{
public:
int id;
int descendant;
int ancestor;
string text;
};
class Dialogue
{
public:
int id;
int trigger;
Question descendants[5]; // Max questions per dialogue
string text;
};
答案 3 :(得分:1)
交换类声明的顺序:
class Question
{
public:
int id;
int descendant;
int ancestor;
string text;
};
class Dialogue
{
public:
int id;
int trigger;
Question descendants[5]; // Max questions per dialogue
string text;
};