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 7618483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:57+00:00 2026-05-31T03:24:57+00:00

Why do I get error C2504: ‘CEntity’ : base class undefined errors, when all

  • 0

Why do I get “error C2504: ‘CEntity’ : base class undefined” errors, when all the relevant headers are included?

I have a CMap which does most of the heavy lifting:

// CMap.h
#ifndef _CMAP_H_
#define _CMAP_H_
#include "CEntity.h"
class CMap {
    public:
        CMap(void);
        void OnLoad();
        void OnRender();
        std::vector<CTile*> TileList;
};
#endif

One of the things in the CMap is a list of Tiles:

// CTile.h
#ifndef _CTILE_H_
#define _CTILE_H_
class CEntity; // forward declaration

class CTile {
    public:
        CTile(void);
        std::vector<CEntity*> EntityList;
        char Label[0];
};
#endif

Each Tile contains a list of Entities:

// CEntity.h
#ifndef _CENTITY_H_
#define _CENTITY_H_
class CEntity {
    public:
        CEntity(void);
        char Label[0];
};
#endif

There are also various children of CEntity:

// CEntity_Buggy.h
#ifndef _CENTITY_BUGGY_H_
#define _CENTITY_BUGGY_H_
#include "CEntity.h"
class CEntity_Buggy : public CEntity {
    public:
        CEntity_Buggy(void);    
};
#endif

Now, my main map loading routine works fine, as does the rendering routing, which happens to need to peek into the Tiles for some info:

// CMap.cpp
#include "CMap.h"

void CMap::OnLoad() {
    ...
}

void CMap::OnRender() {
    /* here would be some rendering code ... */

    std::vector<CTile*>::iterator i;
    for (i=this->TileList.begin(); i!=this->TileList.end(); ++i) {
        CTile* tile = *i;

        for(unsigned int i = 0; i < tile->EntityList.size(); i++) {
            label[0] = tile->EntityList[i]->Label[0];
        }
    }
}

That works fine, and in the full app so far, it draws the cells, and adds the labels from the ‘resident’ entities.
The problem comes when I want to put some specific entity subclasses into the system:

// CMap.h
#include "CEntity_Buggy.h" // add this to the header

// CMap.cpp
#include "CMap.h"

void CMap::OnLoad() {
    CEntity_Buggy buggy;
    buggy.OnLoad();
}

And now I get lots of \centity_buggy.h(18): error C2504: 'CEntity' : base class undefined errors, but I’m not sure why. My CEntity_Buggy.h includes CEntity.h.

The full current (and this is a first-C++ project, so it’s quite flawed) is available on GitHub, if that helps.

  • 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-31T03:24:59+00:00Added an answer on May 31, 2026 at 3:24 am

    The specific cause here is, I suspect, this chain of includes:

    • CEntity.h includes CCamera.h
    • CCamera.h includes CMap.h
    • CMap.h includes CEntity_Buggy.h

    So CEntity.h is causing CEntity_Buggy.h to be included before CEntity has been defined. In this case it does not look like CMap.h really needs CEntity_Buggy.h – you could probably just include it in the cpp.

    In general avoid including in .h files wherever humanly possible. Forward declaration is your friend 🙂

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

Sidebar

Related Questions

I have this query and I get error Operand should contain 1 column(s), whats
I have created Controller Attribute and would like to read SessionId but get error
I have get error with the following code and i can't figure it out.
I get error C2027: use of undefined type 'Bridge' and error C2227: left of
so I get error when I use bgstretcher, all links are correct to scripts,
I get error: ORA-06575: Package or function GET_CONC_NAMES is in an invalid state When
Why I get error with this query on my live server but not on
What is the best way to get error messages from a WF4 workflow back
I use the following jquery statements but i get error in this function onGetDataSuccess(result)
I am using following PHP code for trigger creation but always get error, please

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.