Linked Questions

207 votes
4 answers
102k views

Does std::make_unique have any efficiency benefits like std::make_shared? Compared to manually constructing std::unique_ptr: std::make_unique<int>(1); // vs std::unique_ptr<int>(...
NFRCR's user avatar
  • 5,618
1 vote
1 answer
155 views

Say if I have this definition: class A { A(); std::unique_ptr<B> m_b; }; class B {}; Is there a difference if I initialize A like: A::A() : m_b(new B()) {} vs. A::A() : m_b(std::...
John Tan's user avatar
  • 1,385
136 votes
6 answers
46k views

As far as I understand, C++14 introduced std::make_unique because, as a result of the parameter evaluation order not being specified, this was unsafe: f(std::unique_ptr<MyClass>(new MyClass(...
Eternal's user avatar
  • 3,114
9 votes
2 answers
4k views

A simple code class Base {}; class Derived : Base {}; unique_ptr<Base> Create() { unique_ptr<Base> basePtr = make_unique<Derived>(); // compile error return basePtr; } ...
Dejan's user avatar
  • 1,028
2 votes
3 answers
5k views

In my project I need container that holds smart pointers to an data unit instances. I write the class (simple example): template <typename T> class Queue { public: void push(const T & ...
Yura's user avatar
  • 1,214
4 votes
3 answers
2k views

How can I decide when choosing between std::containers (std::vector or std::array) and smart pointers pointing to arrays I know containers are objects for memory managment. They are exception safe ...
Aris's user avatar
  • 138
2 votes
3 answers
790 views

Is there a transparent way of using std::unique_ptr in containers? #include <iostream> ...
Konrad Eisele's user avatar
4 votes
1 answer
1k views

I am currently learning C++, coming from C#/Java background, using visual studio 2017. I have a question in regards to creating objects on heap and referencing them properly down the road. So far I ...
AleksanderNaumenok's user avatar
2 votes
1 answer
2k views

I'm trying to define a Data object that contains its size, followed by size bytes of data. Something like: struct Data { size_t size; char data[1]; static void* operator new( std::...
Helloer's user avatar
  • 467
0 votes
2 answers
1k views

I have some objects of a same class in an array that was pointed by a unique_ptr, and each object can only be created with the explicit constructor, since a few of arguments must be passed to the ...
Leon's user avatar
  • 2,165
0 votes
0 answers
853 views

I was looking at this Arduino code sample (https://buger.dread.cz/simple-esp8266-https-client-without-verification-of-certificate-fingerprint.html): std::unique_ptr<BearSSL::WiFiClientSecure>...
Rahul Iyer's user avatar
  • 21.1k
0 votes
3 answers
243 views

struct abc { float b; }; abc* xyz; xyz->b = 10; printf("%f", xyz->b); error at printf. What is the reason? How can I solve this?
user6532's user avatar
3 votes
2 answers
314 views

I was implementing classes my_unique_ptr and my_shared_ptr that mimic the standard library smart pointers std::unique_ptr and std::shared_ptr to get to know it better. When implementing the ...
Siraj Qazi's user avatar
1 vote
2 answers
205 views

What I am trying to achieve is creating a superclass array of subclass objects. In this particular test I'm working on, I want to have an animal array that has some dog objs and some cat objs while ...
Leona Huang's user avatar
1 vote
1 answer
184 views

I have seen this answer (Advantages of using std::make_unique over new operator) where it states: Don't use make_unique if you need a custom deleter or are adopting a raw pointer from elsewhere. ...
Andrew Truckle's user avatar

15 30 50 per page