Is there a way to get a base class name in C++ at runtime?
You can get the current class name, assuming RTTI is enabled, using typeid(this).name() at runtime.
I would like to be able to get the name of the base class for "this". Is that possible? I'm not usin开发者_运维知识库g multiple inheritance, in case that makes a difference.
Plus, I don't think that you can count on typeid(this).name()
to give you a class name (AFAIK the exact value to be returned is implementation-defined).
No sir. Sorry. And your method of getting the class name this way is implementation-dependent. On my implementation, I get the mangled name.
The information can't reliably be retrieved because it isn't reliably stored anywhere, in turn because the C++ philosophy is not to give you things unless you explicitly ask for them.
No, it is not, and the reason you need this feature is dubious :)
精彩评论