C++ 预处理宏来获取当前类的名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5427099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Preprocessor macro to get the name of the current class?
提问by Damian
Similar to what __FUNCTION__
does for the current function, Is there a preprocessor macro to get the name of the current class?
类似于__FUNCTION__
当前函数的作用,是否有预处理器宏来获取当前类的名称?
采纳答案by Adam Trhon
回答by Alexander Gessler
No, there is no such macro - sorry.
不,没有这样的宏 - 抱歉。
But nevertheless: __FUNCTION__
(or __PRETTY_FUNCTION__
with gcc) should give you the name of the enclosing class - you just have to extract it.
但是:(__FUNCTION__
或__PRETTY_FUNCTION__
使用 gcc)应该给你封闭类的名称 - 你只需要提取它。