I have this sample code:
std::unique_ptr<Base> some_function() {
//I cannot use unique ptr here becuase it will get freed when the function return i guess
Derived* derived = new Derived;
return static_cast<std::unique_ptr<Base>>(derived);
}
Is using static_cast here is a good solution?
Are there other alternatives to return unique_ptr?
And
return std::unique_ptr<Command>(derived);
if I return like this, will the ptr be freed at the end of the return expression since it is anynomous?
And what is the workaround if I don't want to use raw pointers in Derived* derived = new Derived;?