Questions tagged [smart-pointer]
For questions about the usage of the smart pointer construct.
34 questions
-1 votes
1 answer
162 views
Smart pointer class choice: Simplicity vs. right tool for the job
I'm wrestling with a design choice question here. I've got a class that needs a couple of semaphores. Semaphores are non-movable objects. Objects of this class however need to go into a vector (there'...
2 votes
1 answer
3k views
How to store a vector of smart pointers, except some of them are owned by another object?
I'm making a basic platformer game. I have a Game class as well as Level class. The game object holds a pointer to the current Level object. A level currently has a std::vector of GameObject raw ...
1 vote
2 answers
232 views
Develop a distributed pointer in C++
I s it possible to develop a distributed memory pointer in C++ by using operator overload? The idea would be that you pass ip address and port to the overloaded pointer *, &, and the pointer ...
8 votes
2 answers
17k views
Should I use a unique_ptr with an array type, or a vector?
I've been out of C++ for years, last time I used it was back in gamedesign before C++11. I see all these new pointer types which seem great. But I'm unsure when and how to use them. In the old days I ...
12 votes
4 answers
22k views
Using vectors of shared pointers to objects in my C++ code to prevent object duplication
In my C++ project, I have three classes, Particle, Contact, and Network. The Network class will have N particles (std::vector<Particle> particles) and Nc contacts (std::vector<Contact> ...
1 vote
1 answer
4k views
How can I copy and alter object with unique_ptr in it?
I basically have the following situation: +------------------+ | | | Input object | ...
1 vote
1 answer
1k views
Mocking of non-copyable objects
I find myself often in the situation where I want to mock a non-copyable object, for example a DbHandle handle. I was going back and forth looking at different design choices, and I settled on the ...
4 votes
1 answer
4k views
Unique pointer initialisation
What is the correct initialisation of a smart pointer? std::unique_ptr<Class> ptr(std::make_unique<Class>()); or std::unique_ptr<Class> ptr = std::make_unique<Class>(); Is ...