Copying derived entities using only base class pointers, (without exhaustive testing!) - C++

后端 未结 4 1154
感情败类
感情败类 2020-12-02 17:15

Given a base class that is inherited by plethora of derived classes, and a program structure that requires you manage these via base class pointers to each entity. Is there

4条回答
  •  失恋的感觉
    2020-12-02 17:40

    Yeah, your idea is the way to go. It also allows the derived classes to choose whether they wish to perform a deep or shallow copy.

    I have one (somewhat nit-picky) point for future reference: in terms of safety, using dynamic_cast is preferred to static_cast for polymorphic conversions. It's just one of those things that grabs my attention.

提交回复
热议问题