Getting a vector<Derived*> into a function that expects a vector<Base*>
问题 Consider these classes. class Base { ... }; class Derived : public Base { ... }; this function void BaseFoo( std::vector<Base*>vec ) { ... } And finally my vector std::vector<Derived*>derived; I want to pass derived to function BaseFoo , but the compiler doesn\'t let me. How do I solve this, without copying the whole vector to a std::vector<Base*> ? 回答1: vector<Base*> and vector<Derived*> are unrelated types, so you can't do this. This is explained in the C++ FAQ here. You need to change your