How to create a pointer after creating shared_ptr?
std::shared_ptr<Investment> createInvestment() { std::shared_ptr<Investment> retVal(static_cast<Investment*>(0), getRidOfInvestment); // как тут передать в retVal указатель. return retVal; } How to create a pointer after creating shared_ptr?
std::shared_ptr<Investment> createInvestment() { std::shared_ptr<Investment> retVal(static_cast<Investment*>(0), getRidOfInvestment); // как тут передать в retVal указатель. return retVal; } You have a strange function, but if you really need it, you can use the reset function:
retVal.reset(newInvestment, getRidOfInvestment); You can create a smart pointer shared_ptr two ways:
1) call the shared_ptr constructor, passing a pointer to the finished, already constructed object that it controls
std::shared_ptr<Investment> retVal(new Investment()); 2) use the special method make_shared , which creates an object of type T and returns the "smart" pointer of this class.
std::shared_ptr<Investment> retVal = std::make_shared<Investment>(); shared_ptr , but on interfaces. True, it still does not justify such a code, he could use a better example. - ixSciSource: https://ru.stackoverflow.com/questions/864683/
All Articles
tr1not needed, instead ofstatic_cast<Investment*>(0)you can writenullptr- VTTshared_ptrwas only in a project intr1. Perhaps then everything was somewhat different. - AnT