I've read some examples at Wikipedia but I'm looking for some real-life examples: how is introspection used, why (does it help to write clean code) and the code itself.
For example, is there a way to create a "generic" function to serialize any kind object? I mean: only one function in the parent, and all the descendent could be able to "save" + "restore" themselves into/from a file.
It isn't used (since it doesn't exist), there's no code examples (since it doesn't exist), and there's no reason to attempt to use it (since it doesn't exist).
The closest you can get is RTTI/dynamic_cast. But that's not really introspection.
There's RTTI in C++, and you can also use conditionals and dynamic_cast<>() to this effect, but in C++ we commonly strive to do as much as we can at compile time. If you feel a need for introspection chances are there are Better(tm) ways to achieve what you're aiming at with a static approach.
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