0

我有 6 个 C++ 头文件。有很多包含,所以我尝试制作它,以便我尽可能少地使用。但是我从一开始就一直收到一个错误,说“代理”类是未定义的。我定义了它并包含它,但在这里找不到问题是导致问题的 2 个头文件:

辛巴达.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 {

代理.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
4

3 回答 3

2

看起来有些东西Agent在定义之前引用了类,即可能在aStar.h.

编辑:在您的源代码中搜索#define AGENT_H任何地方。如果您在外面的任何地方找到它Agent.h,这意味着Agent该类可能永远不会被定义,如果只是因为Agent.hcan be #includedwith AGENT_Halready #defined

于 2010-11-10T01:03:47.293 回答
1

不要AgentSinbad.h. 你已经包括了Agent.hAgent.h在withGrid和中似乎也是如此Astar

于 2010-11-10T17:31:27.360 回答
1

一些评论表明您不确定前向声明的工作原理。

当您需要告诉编译器该类型存在但不需要对其进行任何定义时,前向声明一个类型。通常,当类的成员或方法只有对该类型的指针或引用时,这是在标头中完成的。为了执行任何涉及取消引用指针或使用引用的操作,您需要包含定义类型的标头,通常在定义类方法的源代码中。

于 2010-11-11T00:24:41.420 回答