I
I
int_index2011-12-17 01:03:37
C++ / C#
int_index, 2011-12-17 01:03:37

C++11 smart pointers?

There are abstract classes in the code. Naturally, you have to use pointers to work with them; known to me, there are shared_ptr and weak_ptr, where several pointers can point to one object, and unique_ptr, where instead of copying, there is a transfer.
I need such a smart pointer that each pointer is the owner of one object, and when the pointer is copied, the object is copied (as I understand it, the .clone() method cannot be dispensed with here). At the moment I have my own implementation, but it seems to me that I invented the wheel.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wolong, 2011-12-17
@Wolong

“a pointer that owns a unique object, and when the pointer is copied, the object is copied ...” - can you use the object itself without any pointers? overload copy constructors and assignment operator and go ahead. what is the difference from what you need?

A
Alexey Sidorov, 2011-12-17
@Gortauer87

Firstly, you want something strange, and secondly, look at Qt's QSharedData and QSharedDataPointer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question