Why is usage of the typeid keyword bad design?

前端 未结 3 1094
不思量自难忘°
不思量自难忘° 2021-01-02 03:17

I have heard a lot of people say any usage of typeid is bad design, yet to me it seems like it offers great utility.

  1. When (and why) is usage of
3条回答
  •  时光说笑
    2021-01-02 03:51

    I don't think anyone says that usage of typeid is itself bad design; rather, what you'll hear is that usage of typeid is indicative of bad design. The idea there is that any logic that distinguishes (say) Square from Circle should actually be in those classes, so should be expressed by a virtual function (polymorphism).

    Needless to say, this is not an absolute rule.

提交回复
热议问题