Whole vector transmission

Is it possible to distinguish std::vector<std::shared_ptr<Object>>from std::vector<std::shared_ptr<SpecializedObject>>where it SpecializedObjectinherits Objectwithout creating a new array (or iterating through a vector)?

+4
source share
1 answer

The short answer is no.

Long answer:

std::vector<std::shared_ptr<Object>>and std::vector<std::shared_ptr<SpecializedObject>>- completely different and unrelated animals, and you cannot cast them from one type to another. You have to iterate over the vector and create a new one.

Hint: you can still use static_pointer_castto indicate pointers during iteration (if you know what you are doing, of course).

+6
source

Source: https://habr.com/ru/post/1672740/


All Articles