質問

Are there introspection techniques in C++ like those in python?

For example: I want to get more information about a specific object without going through the header file or referring back to cpp reference.

Am I asking a proper question, or moving the wrong direction here?

Update:

Based on the below answers, this answer is related to my question: How can I add reflection to a C++ application?

役に立ちましたか?

解決

C++ has a built in RTTI system, though it's for the most part horribly worthless. As a result custom introspection used instead.

Introspection in C++ is implemented with two main methods: preprocesing step where you scan cpp files and create a database/generate CPP code; use templating. I wrote some articles on the templating technique here.

If you're more interested in just using introspection rather than implementing it, I suggest looking up clReflect, or you can try cpfg.

他のヒント

Python and C++ are radically different languages. Normally, almost all of the type information is lost once you've finished compiling. About all you can do is ask if an object is a specific class (using typeid), or if it is an instance of a specific class (using dynamic_cast). In theory, you can also get the name of the type, using typeid::name(), but in practice, the standard doesn't impose anything useful for the return value, and some compilers (e.g. g++) don't give you anything useful.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top