Virtual base class data members

前端 未结 5 2086
我在风中等你
我在风中等你 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:18

    a) members should be private - so you may get problems using them in derived classes (so you have to add getter and setter methods, which blow up your interface)

    b) don't declare things you currently don't use - declare variables only in classes which access/use them

    c) virtual base classes should only contain the interfaces/virtual methods, nothing more

    I hope that helps a little bit, even if my reasons are not perfect and complete :)

    ciao, Chris

提交回复
热议问题