繁体   English   中英

C ++代理:游戏中的基类未定义错误

[英]C++ Agent : Base class undefined error in Game

我有6个C ++头文件。 有很多包含项,因此我设法做到这一点,以便我尽可能少地使用。 但是我从一开始就一直在说“ Agent”类是未定义的错误。 我定义并包含了它,但找不到问题,这里是引起问题的2个头文件:

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

看起来好像是在定义类Agent之前引用了它,即可能在aStar.h

编辑:在您的源代码中的任何地方搜索#define AGENT_H 如果你发现它以外的任何地方Agent.h ,这意味着Agent类可能永远不会被定义,如果仅仅是因为Agent.h可以#includedAGENT_H已经#defined

不要在Sinbad.h重新声明类Agent 您已经包含了Agent.h GridAstar Agent.h似乎也是如此。

有些评论表明您不确定向前声明的工作方式。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM