4

別のクラス内でクラスを定義するにはどうすればよいですか。以下のコードで。#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 ‘&amp;’ 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

2 に答える 2

3

#define "CCompField.h"それを含める必要がある代わりに:

#include "CCompField.h"

あなたはまた、余分なペアを持っています

#ifndef CNEWGAME_H
#define CNEWGAME_H  

しかし、1つだけ閉じ#endifます。#ifndef/の 2 番目のペアは必要ありません#define

于 2012-06-12T17:58:34.277 に答える
1

#define "CCompField.h" のように定義しようとしましたが、うまくいきません。:(

CCompFieldが定義されているヘッダー ファイルを把握する必要があり#includeます。#defineCNewGame.h

于 2012-06-12T17:58:03.790 に答える