4
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 Game

4

4 回答 4

3

或者您可以转发声明您的课程。当它们都相互依赖时,这很方便:

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; };

于 2013-02-27T02:19:10.817 回答
1

您需要切换定义,以便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;
};
于 2013-02-27T02:15:31.550 回答
1

类 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;
};
于 2013-02-27T02:15:48.920 回答
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;
};
于 2013-02-27T02:16:11.110 回答