Jump to content
  • Advertisement
Sign in to follow this  

Error 2061 - Class Becomes "Undefined" When I Include A Header

This topic is 2391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is very strange and I can't get my head around what is causing it.... So I have two classes, Player and Enemy and a utility static class CollisionMgr.

I have an array of Enemies in the world class, I'd like to have a pointer to it in the Player class for collision detection. But the moment i try to #include the Enemy class in the player one, I get "Player undefined" error in the Enemy one.... I think it has to do with the header inclusions...



#pragma once
#include <string>
#include <vector>

#include "mathlib.h"
#include "md2model.h"
#include "Object3DS.h"



const float PLAYER_FORWARD_SPEED = 60.0f;
const float PLAYER_HEADING_SPEED = 60.0f;

class Player : public GameObject
{
public:

Player(float r);
~Player();

void loadModel(const char *filename);
void drawModel();
void drawBoundingWireframe();
void passVisibleObjects(vector<Object3DS*> &vo);

private:
Entity3D entity;
MD2Model* player;

float modelRot;
float modelPitch;

Vector3 scale;
Vector3 pos;
Vector3 rot;

float forwardSpeed;
float heading;

float radius;


vector<Object3DS*> visibleObjects;

};



And this is the Enemy class


#pragma once
#include <string>
#include <vector>

#include "Player.h"
#include "mathlib.h"
#include "md2model.h"


const float ENEMY_FORWARD_SPEED = 60.0f;
const float ENEMY_HEADING_SPEED = 60.0f;

class Enemy : public GameObject
{
public:

Enemy(Player* p, float r);
~Enemy();

void loadModel(const char *filename);
void drawModel();
void drawBoundingWireframe();


bool checkCollision();

void setPosition(Vector3 pos);
void setRotation(Vector3 r);
void setScale(Vector3 r);


void setSpeed(float s);
void setHeading(float h);
float getForwardSpeed();
float getHeading();
void rotateModel(float dx, float dy);
void resetRotation();

void setAnimation(char *filename);

Vector3 getPosition();
void moveEnemy(float elapsedTimeSec);

Entity3D entity;

void passVisibleObjects(vector<Object3DS*> &vo);



private:
MD2Model* enemy;

Player* player;

float modelRot;
float modelPitch;

Vector3 scale;
Vector3 pos;
Vector3 rot;

float forwardSpeed;
float heading;

float radius;

vector<Object3DS*> visibleObjects;

};


In the source files i include this static class with some collision functions:

#pragma once


#include <vector>
#include "mathlib.h"
#include "Object3DS.h"

#include "Enemy.h"

class CollisionMgr{


public:

static vector<Object3DS*> findVisibleObjects(BoundingBox &viewingVolume, vector<Object3DS> &gameObjects, vector<Object3DS*> &visibleObjects);
static vector<Enemy*> findVisibleEnemies(BoundingBox &viewingVolume, vector<Enemy> &enemies, vector<Enemy*> &visibleEnemies);
static bool checkCollision(const Vector3 pos, const Vector3 forward, float radius, const vector<Object3DS*> &vo);
static double intersectRaySphere(Vector3 rO, Vector3 rV, Vector3 sO, double sR);


};



All of these compile ok like this, but the moment I try to add #include "Enemy" in Player I get error C2061: syntax error : identifier 'Player' inside the Enemy class....

I tried re arranging the include statements but I really don't get what is causing this?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!