When is using 'typeid' the best solution?

后端 未结 6 426
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 10:16

There are many reasons not to use typeid. Other than for using members of type_info (implementation defined behavior), it is usually (always?) pos

6条回答
  •  甜味超标
    2021-01-01 11:06

    So, excluding usage that relies on the implementation defined behavior, does anybody have a real world example where typeid is the best solution?

    I sometimes use it in debug outputs, to verify that a template argument passed to my function is indeed of a given type. This makes sense in my case since the actual template argument passed to my function is generated by a specialised metafunction and I want to make sure that the right metafunction is used.

提交回复
热议问题