100DaysOfGameDev: Day 33

With a better understanding of inheritance and polymorphism in C++, I dived deeper into the topic of RTTI (Run-Time Type Information). Basic hierarchy navigation is done with dynamic_cast or static_cast. It's also interesting to apply this knowledge to recover interface, when for example writing a deserializer, that would read object info from a file and then make objects based on that. I did a revision on double-dispatch, which I think is a neat little trick to achieve a type resolution based on two or more types. However, we are in this weird relationship with Bjarne of calling each other out, me calling him out in this blog series, and him calling me out in the book. Why? Because in the book it says “If you consider this(double-dispatch) elegant, you need to raise your standards.” Anyhow, he then showed the visitor pattern which I do agree looks quite cool and probably a better alternative, than double-dispatch in most cases. It also talked about the pitfalls of RTTI and when ( 90% of the time) it should be avoided. There's also the typeid(expr) function, which can be useful for diagnostic output, but should be avoided to make horrific switch statements. That's it for today, see you tomorrow!