Are type fields pure evil?

后端 未结 9 1328
旧巷少年郎
旧巷少年郎 2021-02-06 16:27

As discusses in The c++ Programming Language 3rd Edition in section 12.2.5, type fields tend to create code that is less versatile, error-prone, less intuitive, and less maintai

9条回答
  •  不思量自难忘°
    2021-02-06 17:09

    Aren't there costs associated to virtual functions and polymorphism? Like maintaining a vtable per class, increase of each class object size by 4 byptes, runtime slowness (I have never measured it though) for resolving the virtual function appropriately. So, for simple situations, using a type field appears acceptable.

提交回复
热议问题