Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6763663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:30:11+00:00 2026-05-26T14:30:11+00:00

This is very strange and I can’t get my head around what is causing

  • 0

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….or if I include successfully Enemy and then try to include CollisionMgr…. there’s some kind of conflict between them two and the definition of Player but I cant understand how to resolve it….

Am using VS2010 as my compiler..

Any help would be appreciated!

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:30:12+00:00Added an answer on May 26, 2026 at 2:30 pm

    This is a case of a circular dependency. You will need to properly forward declare Player and Enemy and you will not be able to use their definitions in the opposite header file. You can use them in the implementation file. Here’s an example:

    Player.h

    class Player
    {
       // needs to know about Enemy
       void f(const Enemy& b);
    };
    

    Enemy.h

    class Enemy
    {
       // needs to know about Player 
       void f(const Player& a);
    };
    

    Including the header file in both locations will cause an error (like you are seeing):

    Player.h

    // This isn't going to work...
    #include "Enemy.h"
    class Player
    {
       // needs to know about Enemy
       void f(const Enemy& b);
    };
    

    Enemy.h

    // This isn't going to work...
    #include "Player.h"
    
    class Enemy
    {
       // needs to know about Player 
       void f(const Player& a);
    };
    

    What is needed here is a “forward declaration” for Player and Enemy where appropriate, like this:

    Player.h

    // forward declaration:
    class Enemy;
    
    class Player
    {
       // needs to know about Enemy
       void f(const Enemy& b);
    };
    

    Enemy.h

    // forward declaration
    class Player;
    
    class Enemy
    {
       // needs to know about Player 
       void f(const Player& a);
    };
    

    Then in the implementation files you can #include the appropriate headers to actually get the definitions of the objects in your compilation unit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is very strange and I'm hoping someone can help me. For the
This is a very strange problem, and I just hope that I can clearly
it is very strange, because this error doesn't happen all the time... I have
I have this very strange issue with my MVC 2 project. Often times, I'll
This is very strange, maybe someone can explain what's happening, or this is a
This is very strange. I have an XAML file that looks as follows... <Window
I have very strange error I can't understand. I started a new project throw
I have a very strange bug in a shipping iPad/iPhone app that I can't
This code compiles but looks very strange. I have a typical and simple parent/child
I have a very strange issue, that I'm hoping someone here can help me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.