When I inherit from std::enable_shared_from_this, but I create a unique_ptr, will the weak_ptr inside std::enable_shared_from_this also be initialized when I "move" to a shared_ptr by std::move, or by the move constructor?
For example what will happen in the below code:
#include <memory>
#include <iostream>
class A : public std::enable_shared_from_this< A >
{
public:
std::shared_ptr< A > getA()
{
return shared_from_this();
}
};
int main()
{
std::unique_ptr< A > u(new A());
// Aborts
//std::cout << u->getA() << std::endl;
std::shared_ptr< A > s(std::move(u));
// Will this work or abort too?
std::cout << s << ", " << s->getA() << std::endl;
}