It seems everywhere I read that either a library boasts if not needing RTTI or an article advises against its use. What is so bad about it and why is it such a good thing not to need it?
Thanks
Because using it usually means you are subverting polymorphism (if (type is foo) { do this; } else if (type is bar) { do that; } else ...
), which usually means you have engineered yourself into a corner and need to rethink your design.
Because authors of C++ compilers put a lot of effort into optimising polymorphic behaviour, but less so into optimising use of RTTI.
C++ allows a lot of static tricks with templates thus reducing the need of RTTI (everything is generic at the compile time, but concrete at the run-time).
On the contra, the "true" (SmallTalk-like) OOP way of dealing with classes requires dynamic binding and RTTI.
C++ allows both, but excessive dynamic_casts and virtual functions may and do degrade performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With