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
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.
character* characterpointerarray; //store ten character pointers
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.