Virtual base class data members

前端 未结 5 2130
我在风中等你
我在风中等你 2021-01-05 04:30

Why it is recommended not to have data members in virtual base class?

What about function members? If I have a task common to all derived classes is it OK for virtua

5条回答
  •  青春惊慌失措
    2021-01-05 05:25

    I've never seen this recommendation.

    A class is a set of closely related functions and data. The purpose of a base class is to have a common set of functions and data that are available for reuse by derived classes.

    I think restricting yourself to not have data members or non-pure virtual functions in base classes will reduce the amount of code reuse, which leads to less reliable code in the long run.

提交回复
热议问题