This problem has been confusing me for quite some time now.
Bascily I need to be able to individually access multiple objects by their name in another function. Ive seen examples where object pointers are pushed into a list but I cant access them by their name that way it seems.
Lets say in one function I create many objects (both hardcoded and dynamically allocated), then in another I use all the objects (draft code btw)
class gameobjects
{
public:
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
};
void createenemies()
{
gameobjects* chief = new gameobjects();
chief->x = 1.0f;
gameobjects* grunt = new gameobjects();
grunt->x = 4.0f;
gameobjects* elite = new gameobjects();
elite->x = 8.0f;
}
void scene()
{
---
chief->x = 9.0f;
---
elite->x = 4.0f;
grunt->y = 8.0f;
---
}
Looking online I cant seem to be able to find a solution to this problem. The class and the function is in the same source file. Ive tried researching how to acess multiple objects by the name in another function, and how to make functions global. Thanks for any help.
edit: Im looking for a way to keep my code neat and up to good standards with just one function that can both dynamically and hardcodely create objects of which can be accessed throughout the program.
edit: Passing through each object to another function wont really be practical in some cases where If want to create many or even hundreds of objects in the createenemiesfunction