The similar questions here all seem to use boost, which I'm not using.
What I'm trying to do is demonstrated by the following:
In the "owner":
std::shared_ptr<State> m_state;
m_state = make_shared<State>(param);
m_state = m_state->SomeVirtualFunction(); // The original m_state object gets destroyed
In the "owned":
std::shared_ptr<State> State::SomeVirtualFunction() {
return std:shared_ptr<State>(this);
}
In Visual C++ in MSVS 2012, the owned object gets destroyed. How can I keep it alive?