#include <memory>
class bar{};
void foo(bar &object){
std::unique_ptr<bar> pointer = &object;
}
I want to assign an address of the object to the pointer. The above code obviously wont compile, because the right side of the assignment operator needs to be a std::unique_ptr. I've already tried this:
pointer = std::make_unique<bar>(object)
But it throws many errors during compilation. How can I do that?
Update
As said in the answers - using the std::unique_ptr::reset
method led to undefined behaviour. Now I know, that in such cases I should use a standard pointer.