【发布时间】:2013-02-12 17:22:08
【问题描述】:
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++ 不支持 默认整数 c:\users**\documents\visual studio 2012\projects\game\game\dialogue.h 8 1 游戏
【问题讨论】:
-
前向声明?类声明的交换顺序
-
我会说这是因为
Question是在Dialogue之后定义的,但是在Dialogue的定义中使用。 -
在将
Question声明为类之前,您正在使用它。在这种情况下,您可以将Question放在Dialogue之上,但有时您需要一个前向声明[class Question;] 来告诉编译器有一个该名称的类。
标签: c++ class identifier