I am having some issues wrapping my brain around how use a function to create an object in a queue. Below is my current relevant code. I am creating a pointer for the object as the object will be one of several children based on user input.
I understand that this code is wrong because I am attempting to return a pointer as an object, but I am just not sure how to pass or create the object around the function in a correct manner.
However, using new in any sense requires that you delete your objects as well, unless you're using smart pointers.
With smart pointers, you can simply create a container of smart object pointers, and not have to worry about clean up.
1 2 3 4 5 6 7
#include <memory>
typedef std::shared_ptr<MyObject> MyObjectPtr;
//std::shared_ptr<> is one of the smart pointers available.
std::queue<MyObjectPtr> objects;
objects.push_back(MyObjectPtr(new MyObject()));