Are type fields pure evil?

后端 未结 9 1480
旧巷少年郎
旧巷少年郎 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:00

    I think that if the type corresponds precisely to the implied classes then type is wrong. Where it gets complicated is where the type does not quite match or its not so cut and dried.

    Taking your example what if type was Red, Green, Blue. Those are types of shapes. You could even have a color class as a mixin; but its probably too much.

提交回复
热议问题