Im quite new to oop and having trouble with creating new objects inside of others. In my game, I require a bullet to be created in the players update function. The problem is that I have no idea how to add the created object (bullet) to the game list in order for it to be updated. To update game objects I use this:
1 2
for(iter = objects.begin(); iter != objects.end(); ++iter)
(*iter)->Update();
I thought of returning the bullet object in the function but that would increase difficulty of updating all other objects as only specific game objects would return values.
to create a bullet I use:
Bullet *bullet = new Bullet(*Weapon::bullet);
found the players update function
I need to add this object into the objects list but am unsure how to do this as it is contained in the main.cpp file.
Can anyone specify a way in which these created objects can be add to the list?
I didnt know about smart pointers but i just read some documentation on them. Is the purpose in smart pointer just to automatically destroy pointers?
also, i had another idea on creating objects. What if there was a global function called Instantiate that is called whenever an object is created. This can be defined in the main.cpp file as: