Textbased RPG Character Objects

Hey, I'm quite new to c++ programming and trying to get the hang of it through creating a text-based RPG, although I'm having trouble with deciding how to create multiple character slots. At the moment I have a character.cpp class file from which I create the character objects.

Creating the character objects from the characterMenu.cpp class file:

1
2
3
character character1;
character character2;
character character3;


This brought about a new problem, how can I create the objects so ALL of my classes can access them? e.g. if I want to access character2 from the map class.

In short: what is the most efficient way to create multiple character objects which can be accessed across all of my .cpp files?
They are called containers or managers. Essentially what they do is hold pointers to objects. Then you pass the pointer of the manager to the map class which then has access to all the objects contained within the manager.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

class character{};

class characterManager
{
    character* characterpointerarray[10]; //store ten character pointers
};
  
//...

class map
{
public:
  map(){};
  map(charactermanager* characters):myCharacterManager(characters){};

private:

  charactermanager* myCharacterManager;
};


you have a class called character which does nothing.

then there is a charactermanager class which has an array of 10 character pointers.

by passing the map the address of the manager, the map now has access to all the characters in the game that have been added to the manager.
I tried to find other answers online but simply couldn't think of what to search for, thank you for answering in such a fast and easy to understand manner.
Topic archived. No new replies allowed.