Error: "The class has not been declared in this area.

I would like to ask how can I define a class inside another. In the code below. I try to define it like this: #define "CCompField.h", but it doesnโ€™t work. :(. I think this is a very common programming problem, it probably was solved 100,000 times on the Internet, but I donโ€™t know how find her. Thanks for the help.

#ifndef CNEWGAME_H #define CNEWGAME_H class CNewGame{ public: CNewGame(); ~CNewGame(); void BeginnerGame(); void IntermediateGame(); void AdviceGame(); void HowToPlay(); void NetGame( int mode ); int MoveInMenu(); protected: void Intro(); void Animation (); void Menu(int); int MoveInNetMenu(); void NetMenu(int); void HeadOfGame(); template <class T> void BodyOfGame(CCompField & b, T & a); void FooterOfGame(); }; #endif 

He makes the following mistakes.

 In file included from src/CNewGame.cpp:12:0: src/CNewGame.h:37:36: error: 'CCompField' was not declared in this scope src/CNewGame.h:37:45: error: 'b' was not declared in this scope src/CNewGame.h:37:50: error: expected primary-expression before '&' token src/CNewGame.h:37:52: error: 'a' was not declared in this scope src/CNewGame.h:37:53: error: variable or field 'BodyOfGame' declared void 
+4
source share
2 answers

Instead of #define "CCompField.h" you need to enable it:

 #include "CCompField.h" 

You also have an extra pair

 #ifndef CNEWGAME_H #define CNEWGAME_H 

but only one closure of #endif . You do not need a second pair #ifndef / #define

+3
source

I try to define it like this: #define "CCompField.h", but it doesnโ€™t work. :(

You need to find out the header file where CCompField defined and #include (not #define ) is from CNewGame.h .

+1
source

All Articles