Is it possible to cast a std::vector<std::shared_ptr<Object>> to an std::vector<std::shared_ptr<SpecializedObject>> where SpecializedObject inherits Object, without building a new array (or iterate through the vector)?
Short answer: no.
Long answer:
std::vector<std::shared_ptr<Object>> and std::vector<std::shared_ptr<SpecializedObject>> are completely different and unrelated beasts and you cannot cast from one type to the other one.
You must iterate through the vector and create a new one from that.
Hint: you can still use static_pointer_cast to cast the pointers while iterating (if you know what you are doing, of course).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With