2010-11-10 19 views
0

我有6個C++頭文件。有很多內容,所以我儘量使它儘可能少地使用。但是我從一開始就不斷收到一個錯誤,說一個類「Agent」是未定義的。我定義它,它包含的,不能在這裏找到問題是導致問題的2頭文件:C++代理:遊戲中的基類undefined錯誤

Sinbad.h:

#ifndef SINBAD_H 
#define SINBAD_H 

#pragma once 
#include "Agent.h" 

#define NUM_ANIMS 13 // number of animations the character has. Should be made character specific 

class Agent; 

class Sinbad : public Agent { 

Agent.h:

#ifndef AGENT_H 
#define AGENT_H 

#include <deque> 
#include "aStar.h" 

extern Ogre::SceneManager* sceneMgr; // Defined in main.cpp 

class GridNode; // forward declarations 
class Grid; 
class Astar; 

class Agent { 

下面是我收到的錯誤:

1>c\gameengine_solution\sinbad.h(12) : error C2504: 'Agent' : base class undefined 
+0

具體的錯誤會有幫助 - 你可能實際上在其他地方有問題。 – birryree 2010-11-10 01:07:46

+0

看來這個錯誤來自Sinbad.h文件。 – 2010-11-10 01:24:49

+0

你爲什麼要轉發宣告Astar?它不是在Star.h中定義的嗎? – Craig 2010-11-10 01:59:33

回答

2

在定義它之前,它看起來像是指類Agent,即可能在aStar.h

編輯:搜索#define AGENT_H無處不在您的來源。如果你發現它在Agent.h以外的任何地方,那意味着Agent類可能永遠不會被定義,如果僅僅因爲Agent.h可以是#includedAGENT_H已經#defined

+0

以下是錯誤代碼: 1> c:\ gameengine_solution \ sinbad.h(12):錯誤C2504:'代理程序':基類未定義 – 2010-11-10 01:21:01

+0

謝謝。那工作。 – 2010-11-10 19:27:11

1

不要在Sinbad.h中重新聲明Agent類。您已包含Agent.h。在Agent.hGridAstar似乎也是這種情況。

1

一些評論表明你不確定如何向前宣佈作品。

當你需要告訴編譯器該類型存在但不需要任何定義時,前向聲明一個類型。一般來說,當一個類的成員或方法只有指針或類型的引用時,這是在頭文件中完成的。爲了做任何涉及解引用指針或使用引用的任何事情,您需要包含定義類型的頭,通常在定義類方法的源代碼中。