Is there a way to initialize shared_ptr first with nullptr and after a while get a pointer to the 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 ) ?
ptr.reset( new MyClass )
Use shared_ptr :: reset :
std::shared_ptr<MyClass> ptr; ptr.reset(new MyClass);
It may not be as efficient as calling reset, but it should also work. Create an inline temporary instance of shared_ptr and assign it.
std::shared_ptr<MyClass> ptr; ptr = std::shared_ptr<MyClass>(new MyClass);
Source: https://habr.com/ru/post/1390431/More articles:Cannot start Tomcat 7 from eclipse - javaopencart - How to manually display a module inside a template file? - phpHow to get the row index? - sqlNotepad ++: regex search n times - regexHypervisor Literature - cHow to find the border pixels of each connected component in an image in opencv - cWorking with Javascript buffer after section has been copied from website - javascriptGeoJSON: Are FeatureCollection properties allowed? - geojsonWhat is the purpose of maxNumberOfServerInstances in the NamedPipeServerStream class? - .netHow do you translate the elements of an array and join them? - twigAll Articles