typeid.name() not changing when iterating through a vector. Dynamic cast and typeid a base class pointer

前端 未结 2 1155
北海茫月
北海茫月 2021-01-21 11:53

Answer: In short use virtual functions! So don\'t actually use this as good design, but for learning purposes take a read!

I want to start off by saying I am using c++ a

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 12:16

    For dynamic cast to work, any of the function in base class must be virtual, that mean base class must be used in polymorphic way.

提交回复
热议问题