I have a class Base
:
class Base
{
};
and a derived class Derived
:
class Derived: public Base
{
};
Now I need to get a vector of Derived Pointers:
std::vector<std::shared_ptr<Derived>> derivedVec;
but they are stored unfortunately as a vector of Base Pointers, e.g. I can access only the downcasted pointers:
std::vector<std::shared_ptr<Base>> baseVec;
How to I perform the conversion from std::vector<std::shared_ptr<Base>>
to std::vector<std::shared_ptr<Derived>>
. The solution is desired to be C++20 style.