Why is unique_ptr<T> not assignable from *T?

  c++, unique-ptr

What’s "wrong" with this code, for a simple-minded example?

unique_ptr<char> meow = strdup("meow");

Whether or not I provide the "deleter" argument to the unique_ptr template, a unique_ptr<T> cannot be assigned from *T.

Why wouldn’t <memory> offer this seemingly intuitive shortcut? Is it simply an oversight, or would such assignability be a fundamentally bad idea for some reason?

Source: Windows Questions C++

LEAVE A COMMENT