I would like to ask, how can I define class inside another one. In the code below. I try to define it in the way #define “CCompField.h” ,but it doesn’t work. :(.
I think that it is very common programming problem, probably it was 100000 times solved on the internet, but I don’t know how to find it. Thanks for 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
It makes following errors.
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
Instead of
#define "CCompField.h"you need to include it:You also have an extra pair of
but only one closing
#endif. You don’t need the second pair of#ifndef/#define