Practical use of dynamic_cast?

Toy example Noah’s ark shall function as a container for different types of animals. As the ark itself is not concerned about the difference between monkeys, penguins, and mosquitoes, you define a class Animal, derive the classes Monkey, Penguin, and Mosquito from it, and store each of them as an Animal in the ark. Once … Read more

When can compiling c++ without RTTI cause problems?

Since your question is specific to GCC you should consult carefully the documentation for the version you are using. The documentation for GCC 4.5.2 says the following. Which from my reading would indicate that if you avoid dynamic_cast and typeid, you should be ok. That said, I have no personal experience with -fno-rtti. Perhaps you … Read more

What can make C++ RTTI undesirable to use?

There are several reasons why LLVM rolls its own RTTI system. This system is simple and powerful, and described in a section of the LLVM Programmer’s Manual. As another poster has pointed out, the Coding Standards raises two major problems with C++ RTTI: 1) the space cost and 2) the poor performance of using it. … Read more

Which is faster between is and typeof

Does it matter which is faster, if they don’t do the same thing? Comparing the performance of statements with different meaning seems like a bad idea. is tells you if the object implements ClassA anywhere in its type heirarchy. GetType() tells you about the most-derived type. Not the same thing.

How expensive is RTTI?

Regardless of compiler, you can always save on runtime if you can afford to do if (typeid(a) == typeid(b)) { B* ba = static_cast<B*>(&a); etc; } instead of B* ba = dynamic_cast<B*>(&a); if (ba) { etc; } The former involves only one comparison of std::type_info; the latter necessarily involves traversing an inheritance tree plus comparisons. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)