Using std::unique_ptr for down cast

Flaviu_ 991 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,730 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.