If this is for lifecycle management, then:
std::queue<std::shared_ptr<int>> CheckoutLine; CheckoutLine.push(std::make_shared<int>(firstValeToBePushed))
If your queue looks like a proxy server, and someone really owns the lifetime of the objects, then definitely:
std::queue<std::reference_wrapper<int>> CheckoutLine; CheckoutLine.push(firstValeToBePushed)
If you do not put the queue anywhere and inside it, then keeping the pointers in order, like the others.
However, NEVER NEVER provides a client with a collection of pointers that the worst thing you can do is when you leave the burden of managing life time on them and that messier in the collections.
Of course, for primitive types or POD just copying is in order, there is no need to store pointers. Moving semantics makes it easy even for non-PODs if you donβt have a complex design or you cannot implement move semantics.
#include <functional> for std::reference_wrapper and #include <memory> for std::shared_ptr , std::unique_ptr and friends. I assume that you have access to a modern compiler.
source share