[Cs3] unique_ptr reset() and make_unique

Mikhail Nesterenko mnestere at kent.edu
Wed Nov 20 15:41:09 EST 2024


CS3 students,

There was a discussion about using make_unique to reset a pointer.
Like so:

      unique_ptr<MyClass> p;
      p.reset(make_unique<MyClass>);

Apparently, it is not a thing. unique_ptr::reset() expects a raw
pointer. Simple assignment can be used with make_unique for this
purpose:

      p=make_unique<MyClass>; 

Here is a link with more info:

     https://stackoverflow.com/questions/22796788/why-doesnt-make-unique-work-with-unique-ptrreset

Thanks,
-- 
Mikhail


More information about the cs3 mailing list