Getting a vector into a function that expects a vector<Base*>

后端 未结 9 1816
日久生厌
日久生厌 2020-11-29 07:11

Consider these classes.

class Base
{
   ...
};

class Derived : public Base
{
   ...
};

this function

void BaseFoo( std::ve         


        
9条回答
  •  渐次进展
    2020-11-29 07:55

    Instead of passing the container object (vector<>), pass in begin and end iterators like the rest of the STL algorithms. The function that receives them will be templated, and it won't matter if you pass in Derived* or Base*.

提交回复
热议问题