开发者

Is there a way to get a base class name in C++ at runtime?

开发者 https://www.devze.com 2023-01-29 02:39 出处:网络
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

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消