Ravid Goldenberg
Ravid Goldenberg

Reputation: 2299

Smart pointer without reference counter

I had a lesson in programing today and my professor mentioned smart pointers. He said that not every smart pointer needs a reference counter, I am a bit confused... In my understanding the use of smart pointers is to delete an allocated memory after all the pointers and references to it is out of scope. Did I misunderstand? What is the use of a smart pointer without a reference counter?

Upvotes: 1

Views: 63

Answers (1)

Sergey K.
Sergey K.

Reputation: 25396

std::unique_ptr is an example of smart-pointer without a reference counter.

It retains the sole ownership of an object and destroys the object once the unique_ptr goes out of scope.

Upvotes: 1

Related Questions