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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:08:53  来源:igfitidea点击:

Preprocessor macro to get the name of the current class?

c++c-preprocessor

提问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)应该给你封闭类的名称 - 你只需要提取它。