Skip to main content

Questions tagged [smart-pointer]

For questions about the usage of the smart pointer construct.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
164 views

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'...
T.E.D.'s user avatar
  • 1,069
0 votes
1 answer
138 views

I dont exactly know, how to handle the problem, where one class uses shared pointers but I want to call its method from inside other class via this pointer. class Bar { public: Bar() = default; ~...
Martin Perry's user avatar
2 votes
1 answer
3k views

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 ...
Luke B's user avatar
  • 147
6 votes
1 answer
2k views

I am in the process of refactoring a large C++ code (~2300 files, ~600K lines, mostly older C/C++98 style code) and there are definitely memory leaks that could be shored up using C++ smart pointers. ...
wcochran's user avatar
  • 171
1 vote
2 answers
232 views

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 ...
hacker emzeze's user avatar
3 votes
1 answer
3k views

I'm trying to design an API for an object manager that registers and retrieves different related objects. When I want to retrieve an object, I can query it by its object id. I'm wondering if I should ...
Marvg's user avatar
  • 33
8 votes
2 answers
17k views

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 ...
Kevin's user avatar
  • 844
5 votes
1 answer
7k views

Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same. Since all pointers store addresses. Also, the amount of space a pointer will require in ...
amd's user avatar
  • 59
12 votes
4 answers
22k views

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> ...
AnInquiringMind's user avatar
5 votes
2 answers
19k views

I am writing some test units using googletest and googlemock and I am stuck in a problem related to C++11 smart pointers and polymorphism. Suppose you have those classes: class A { public: ...
Marco Stramezzi's user avatar
1 vote
1 answer
4k views

I basically have the following situation: +------------------+ | | | Input object | ...
pluczak's user avatar
  • 13
6 votes
4 answers
963 views

In application which has about 1.5 mln lines of code there is using many pointers as a class members and in other places in code. Classes are usually very huge. It is possible to change to make it ...
marcin's user avatar
  • 79
1 vote
1 answer
1k views

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 ...
user695652's user avatar
1 vote
0 answers
226 views

It is a well-known fact that there is no built-in mechanism that prevents member fields that are references from being invalidated, even if they are const. (For more background see: https://herbsutter....
Lasse Kliemann's user avatar
4 votes
1 answer
4k views

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 ...
bbalchev's user avatar
  • 594
5 votes
2 answers
2k views

So, my Business Code needs some Objects. It does not know how much objects it needs and it does not know the exact types (because polymorphism is involved). For me, that sounds for a good reason to go ...
lugge86's user avatar
  • 445
1 vote
1 answer
359 views

My state machine handles requests and returns the next state. In the below simplification, I've got two states here, CreatedState and RunningState. Running state is the end state, and just returns ...
Nathan's user avatar
  • 1,309
27 votes
5 answers
6k views

Say I have a class Foobar that uses (depends on) class Widget. In good ol' days, Widget wolud be declared as a field in Foobar, or maybe as a smart pointer if polymorphic behavior was needed, and it ...
el.pescado - нет войне's user avatar
3 votes
3 answers
2k views

In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much ...
Oebele's user avatar
  • 215
9 votes
1 answer
3k views

I am developing a database server similar to Cassandra. Development were started in C, but things became very complicated without classes. Currently I ported everything in C++11, but I am still ...
Nick's user avatar
  • 305
3 votes
2 answers
871 views

I'm building a library that generates a couple of types of objects that can be used by user code and the library. To keep track of these objects, I'd like to use shared_ptr's, so I can build in some ...
dawsonc623's user avatar
36 votes
1 answer
31k views

There is a lot of pointers in C++ but to be honest in 5 years or so in C++ programming (specifically with the Qt Framework) I only use the old raw pointer: SomeKindOfObject *someKindOfObject = new ...
CheshireChild's user avatar
10 votes
3 answers
7k views

Assuming we have two classes: class A { ... } class B : public A { ... } Would it be better to write std::deque<shared_ptr<A> > container; or std::deque<reference_wrapper<...
user avatar
1 vote
1 answer
13k views

When creating template classes in C++, if the type upon which the template will be specialized is intended to be a shared_ptr type, is it better to make T a shared_ptr type or make T a non-pointer ...
Matthew James Briggs's user avatar
18 votes
4 answers
4k views

Consider the following singly linked list implementation: struct node { std::unique_ptr<node> next; ComplicatedDestructorClass data; } Now, suppose I stop using some std::unique_ptr<...
VF1's user avatar
  • 1,891
0 votes
3 answers
2k views

I wrote a Chess engine in Java and I am porting it over to C++. I am new to C++. The idea: I have a Board object which holds a 2-dimensionnal array of Piece objects. Queen, Rook, Bishop, etc are ...
Romain's user avatar
  • 117
0 votes
1 answer
206 views

Let me try to elaborate it. Stack Frame: When we execute any function it create stack where all local variables and instructions reside. And Smart Pointer: smart pointer like std::unique_ptr allows ...
twid's user avatar
  • 101
33 votes
5 answers
11k views

Question: Why can't Java/C# implement RAII? Clarification: I am aware the garbage collector is not deterministic. So with the current language features it is not possible for an object's Dispose() ...
mike30's user avatar
  • 2,828
2 votes
2 answers
657 views

I have 3 classes: Meeting, Project and Agenda. A Project contains all sort of information + a list of meetings. The Agenda contains a list of upcoming Meetings. A Meeting contains some data + a list ...
adanselm's user avatar
4 votes
1 answer
2k views

gtkmm provides lifetime management of widgets using Gtk::Widget* aWidget = Gtk::manage(new Widget()); Gtk::Widget.add(*aWidget); This delegates lifetime management of aWidget to its container ...
Vector's user avatar
  • 3,221
9 votes
4 answers
983 views

From what I can see, there are two pervasive forms of resource-management: deterministic destruction and explicit. Examples of the former would be C++ destructors and smart pointers or Perl's DESTROY ...
Louis Jackman's user avatar
73 votes
9 answers
60k views

I was just watching the "Going Native 2012" streams and I noticed the discussion about std::shared_ptr. I was a bit surprised to hear Bjarne's somewhat negative view on std::shared_ptr and his comment ...
ronag's user avatar
  • 1,209
6 votes
2 answers
4k views

Regarding pointers which are members of classes. Should they be of a smart pointer type or is it enough to simply deal with them in the destructor of the class they are contained in?
That Realtor Programmer Guy's user avatar
89 votes
11 answers
33k views

These days, so many languages are garbage collected. It is even available for C++ by third parties. But C++ has RAII and smart pointers. So what's the point of using garbage collection? Is it doing ...
Gulshan's user avatar
  • 9,542