Search code examples
c++ogre3d

C++ Agent : Base class undefined error in Game


I have 6 C++ header files. There are a lot of includes so I tried to make it so that I use as little as I can. But I keep getting an error from the very beginning saying that a class "Agent" is undefined. I defined it and included it and can't find the problem here are the 2 header files that are causing the problem:

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 {

Here's the error I am getting:

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

Solution

  • It looks like something is referring to class Agent before it is defined, i.e. probably in aStar.h.

    EDIT: Search for #define AGENT_H everywhere in your source. If you find it anywhere outside Agent.h, that means the Agent class might never be defined, if only because Agent.h can be #included with AGENT_H already #defined.