Reputation: 97
In the fifth edition of C++ Primer 5th Edition(p. 470):
unique_ptr<T, D> u(d)
: Nullunique_ptr
that points to objects of typeT
that usesd
, which must be an object of typeD
in place ofdelete
.
However, when I tried to supply the deleter function without a pointer object, the compiler(Visual Studio 2015) complains( no instance of constructor matches the argument list.). If I give the unique_ptr
a pointer along with the deleter, it works fine.
So, am I misinterpreting something or is the book just wrong? If the book is wrong, is there any other way I can seperately supply a pointer and deleter to a unique_ptr
?
Upvotes: 0
Views: 135
Reputation: 30418
The constructor you are trying to call doesn't exist. According to MSDN, the only constructors that take a deleter function take a pointer as well. If you want to initialize a unique_ptr
with a deleter but don't want to give it a value yet, you could always pass nullptr
as the first parameter and call unique_ptr::reset()
to give it a pointer to manage later.
Upvotes: 1