is there a way of first initialize shared_ptr with nullptr and after some time assing a pointer to a class to it?
//pseudo code
std::shared_ptr<MyClass> ptr(nullptr);
//and later
ptr->assign(new MyClass);
Are you looking for ptr.reset( new MyClass )
?
Use shared_ptr::reset:
std::shared_ptr<MyClass> ptr;
ptr.reset(new MyClass);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With