vendredi 28 août 2020

Does dynamic_cast work even when thereis no inheritance?

std::bad_cast: https://en.cppreference.com/w/cpp/types/bad_cast

An exception of this type is thrown when a dynamic_cast to a reference type fails the run-time check (e.g. because the types are not related by inheritance)

So, if the types are not related by inheritance then it throws an error, so how it the following quote hold true?

https://stackoverflow.com/a/332086/462608

You can use it for more than just casting downwards – you can cast sideways or even up another chain.

What does this quote mean? Please give examples.

Aucun commentaire:

Enregistrer un commentaire