automatically convert list of pointers to derived class to list of pointers to base class

前端 未结 4 2065
無奈伤痛
無奈伤痛 2020-12-07 03:11

Lets say that I have a base and derived class, and a function that takes an stl vector of pointers to the base class:

class A { public: int x; };

class B :          


        
4条回答
  •  春和景丽
    2020-12-07 03:50

    std::vector and std::vector are technically unrelated. C++ does not allow what you want as such.

    A way around...Why not have a std::vector and insert into it Derived objects? That is the point of polymorphism, dynamic dispatch et al.

提交回复
热议问题