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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:47:46+00:00 2026-05-31T00:47:46+00:00

I am having all sorts of problems with include-overload in my newbie C++ project,

  • 0

I am having all sorts of problems with include-overload in my newbie C++ project, but I’m not sure how to avoid it.

How do I avoid the problem of having to include dozens of classes, for example in a map-loading scenario:

Here’s a trivial example Map class, which will load a game-map from a file:

// CMap.h
#ifndef _CMAP_H_
#define _CMAP_H_
class CMap {
    public:
        CMap();
        void OnLoad();
};
#endif

// CMap.cpp
#include "CMap.h"
CMap::CMap() {
}

void CMap::OnLoad() {
    // read a big file with all the map definitions in it here
}

Now let’s say I have a whole plethora of monsters to load into my map, so I might have a list or some other structure to hold all my monster definitions in the map

std::list<CMonster*> MonsterList;

Then I could simple forward-declare “CMonster” in my CMap.h, and add as many monsters as I like to that list

// CMap.h
class CMonster;

// CMap.cpp
void CMap::OnLoad() {
    // read a big file with all the map definitions in it here
    // ...
    // read in a bunch of mobs
    CMonster* monster;
    MonsterList.push_back(monster);
}

But what if I have lots of different types of monster? How do I create lots of different types of monster without including every CMonster_XXX.h? And also use methods on those?

// CMap.cpp
void CMap::OnLoad() {
    // read a big file with all the map definitions in it here
    // ...
    // read in a bunch of mobs
    CMonster_Kitten* kitty;
    kitty->OnLoad();
    MonsterList.push_back(kitty);

    CMonster_Puppy *puppy;
    puppy->OnLoad();
    puppy->SetPrey(kitty);
    MonsterList.push_back(puppy);

    CMonster_TRex *awesome;
    awesome->OnLoad();
    awesome->SetPrey(puppy);
    MonsterList.push_back(awesome);
}
  • 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-31T00:47:48+00:00Added an answer on May 31, 2026 at 12:47 am

    Here’s the rule I use for including things.

    • Forward declare as much as you can in your header files.
    • include any .h you need in your .cpp
    • don’t include .h in other .h unless you have to.
    • If your project build without needing to include a .h, you are fine. (mostly, provided your compiler is compliant enough)

    Edit: Additionally, you may want to read Large-Scale C++ Software Design. It talks about managing physical file dependencies.

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

Sidebar

Related Questions

I am having all sorts of weird and wacky problems with my pop-up menu
I'm having all sorts of problems implementing styles in action bar, i've read http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
Ok, this might sound like a silly question, but I'm having all sorts of
I've been having all sorts of problems using media queries on a Desire HD
I am having three classes all of them are from different namespaces as shown
I'm writing a LSL to Lua translator, and I'm having all sorts of trouble
I am trying to integrate isotope but Iam having problems getting it to work
I am trying to join three tables together but having a problem getting the
I have a Java background so I’m used to having Maven handle all problem
I'm having all sorts of issues with a stick nav and smooth scrolling. I

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.