Using std::unique_ptr for down cast

Flaviu_ 911 Reputation points
2020-12-09T16:05:33.163+00:00

What is the correct usage of std::unique_ptr for converting to base class a derived class ?

std::unique_ptr<Base*> SomeMethod()
{
    return std::unique_ptr<Derived*>(new Derived());
    return std::make_unique<Base*>(new Derived());
}

?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
{count} votes