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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:41:40+00:00 2026-05-28T17:41:40+00:00

I’m currently trying to make a RPG game and I’m running into some trouble.

  • 0

I’m currently trying to make a RPG game and I’m running into some trouble. This is the layout I have so far.

Classes:

  • Actor – Base class for anything that ‘exists’ such as units, projectiles, etc.
  • Unit – Inherits Actor, basis for all units.
  • Game – It will only have a single instance, and it’ll contains pointers to all objects in the game. I plan to make it call a virtual function gameTick on all actors every 0.1 seconds.

The problem I’m having is that I’d like all Actors to have a pointer to the Game instance. If I wanted to have a spell that does 500 radius area damage, I’d like Game to find and return all Unit pointers within that range.

My problem is if I include Game in Actor’s header file my program won’t compile. How can I have my actors have access to Game? Or am I going about this the wrong way?

Thanks in advance.

// START main.cpp

#include <iostream>
#include "game.h"

int main()
{
    std::cout << "All done\n";

    return 0;
}

// END main.cpp



// START actor.h

#ifndef __ACTOR_H_
#define __ACTOR_H_

#include <iostream>

//#include "game.h" Causes many errors if uncommented

class Actor
{
public:
    Actor();

    std::string name_;
};

#endif

// END    actor.h



// START actor.cpp

#include "actor.h"

Actor::Actor()
{
    name_ = "Actor class";
}
// END actor.cpp



// START unit.h

#ifndef __UNIT_H_
#define __UNIT_H_

#include "actor.h"

class Unit : public Actor
{
public:
    Unit();
};

#endif

// END unit.h



// START unit.cpp

#include "unit.h"

Unit::Unit()
{
    name_ = "Unit class";
}

// END unit.cpp



// START game.h

#ifndef __GAME_H_
#define __GAME_H_

#include <vector>

#include "unit.h"

class Game
{
public:
    std::vector< Actor * > actors_;
    std::vector< Unit * > units_;
};

#endif

// END game.h
  • 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-28T17:41:41+00:00Added an answer on May 28, 2026 at 5:41 pm

    Instead of doing:

    #include "actor.h"
    #include "unit.h"
    

    you can simply forward declare the two classes:

    class Actor;
    class Unit;
    

    Since you’re only using pointers, the compiler just needs to know that the type is a class, it doesn’t need to know anything else. Now in the cpp file, you’d need to do the #includes

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.