What's the preferred C++ idiom to own a collection of polymorphic objects?

后端 未结 4 808
囚心锁ツ
囚心锁ツ 2021-02-02 13:58

Consider the following classes

class Base {
public:
    virtual void do_stuff() = 0;
};

class Derived : public Base {
public
    virtual void do_stuff() { std::         


        
4条回答
  •  猫巷女王i
    2021-02-02 14:12

    Other alternatives worth considering are to use boost::ptr_container, or even better, use a library like adobe::poly or boost::type_erasure for your polymorphic types, to exploit value-based run-time polymorphism—avoids the need for pointers, inheritance, etc.

提交回复
热议问题