C ++ error that I do not understand: syntax is missing ';' before identifier

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

When I try to build this, it says the following error for the bit-descendant of the question:

Error 1 error C2146: syntax error: missing ';' before the identifier "descendants" c: \ users ** \ documents \ visual studio 2012 \ projects \ game \ game \ dialog.h 8 1 Game error 2 Error C4430: missing type specifier - int. Note: C ++ does not support default-int c: \ users ** \ documents \ visual studio 2012 \ projects \ game \ game \ dialog.h 8 1 Game

+4
source share
4 answers

Or you can forward the declaration of your classes. This is convenient when they both depend on each other:

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

+4
source

You need to switch the definitions around, so Question is known to the compiler while you use it in the Dialogue declaration.

This will compile:

 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
source

The definition of the Question class should be the first and then follow the Dialogue class.

 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; }; 
+1
source

The procedure for replacing a class declaration:

 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; }; 
+1
source

All Articles