Can you Initialize all classes once with New?
Greetings. I have a problem with the initialization of my classes I am new self taught C++ and need to understand how I can create a class with a pointer without any new operator, accept for one Initialization() function that initializes all the classes once with the new operator. I have tried this and searched google. When I simply use pointers after I initialize all the classes in one class, I get Access errors if another class tries to access it. The error states that the class/es are not initialized. Only the class with the initialization function can access it.
The issue is that I have many classes. For example the ModelClass () . It will call the ArtItemClass() and take and remove art items. Then another Class, IslandClass() will also access the ArtItemClass() and will take and remove art items. The problem is after each class accesses the ArtItemClass() with a New operator the ArtItems’ set() and get() values as well as all the other specific values that each ArtItemsClass updates (current owner, current value etc…) is lost.
Do I need to create static values for all of the classes that have values that must be maintained and updated, or can I create a pointer somehow so that only one instance of the class exists and can be altered and updated based on preserved values? I would not want to create all forty of my classes into singletons, if that is even an option. Thank you.
here is the code I must place in each function before accessing the ArtItem() class:
m_pArtItems = new ArtItems;
I apologize I could not figure out the code tags