Migrate from raw to smart pointer
Hi I have a code where observer pattern is implemented was in raw pointer format. Code is updated to support smart pointer. Refer code below: https://www.sololearn.com/en/compiler-playground/cLGLnqGQDHVB Issue came in to picture at later moment (It is bad to know at last stage , but this is what it is in current scenario). IObserver* GetUserInfoFromThirdPartyLibrary() is the one which is not in our control. Those third persons are having different priority to update the codebase and still they will return raw pointer instead of smart pointer. To use them into observer, Is below line proper? shared_ptr<IObserver> user5(GetUserInfoFromThirdPartyLibrary()); If not, please suggest why and what should be changed here? Another thing is releasing of heap memory allocated by GetUserInfoFromThirdPartyLibrary. Earlier, I used to call this as below: IObserver* ptr = GetUserInfoFromThirdPartyLibrary(); delete ptr;//at later stage Now, I am not doing any memory release after user5 is constructed. Is this sufficient or will result into memory leak?