【发布时间】:2012-06-15 15:48:16
【问题描述】:
我想问一下,如何在另一个类中定义类。在下面的代码中。我尝试以 #define "CCompField.h" 的方式定义它,但它不起作用。 :(。 我认为这是一个很常见的编程问题,可能在网上解决了 100000 次,但我不知道如何找到它。感谢您的帮助。
#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
它会出现以下错误。
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
【问题讨论】:
-
有什么理由你有两次头部保护?
-
不,我没有两次。我在复制过程中只犯了错误
-
太棒了。如果答案与以下答案之一相同,请选择它作为正确答案。如果没有,请将正确答案发布为您的问题的答案,然后选择它作为正确答案。
-
答案是我只包含了 CCompField 类
-
作为一个新用户,我无法在 8 小时内回答我自己的问题。
标签: c++ class templates declaration