在 C/C++ 中,__PRETTY_FUNCTION__、__FUNCTION__、__func__ 有什么区别?
在本文中,我们将详细介绍 C++ 中的 __FUNCTION__、__func__ 和 __PRETTY_FUNCTION__ 之间有什么区别。
基本上,__FUNCTION__ 和 __func__ 是相同的。某些较旧版本的 C 和 C++ 支持 __func__。此宏用于获取当前函数的名称。__PRETTY_FUNCTION__ 用于返回有关该函数的详细信息。使用这个,我们可以了解使用哪个函数,它属于哪个类,等等。
例如
#include<iostream>
using namespace std;
class MyClass{
public:
void Class_Function(){
cout << "The result of __PRETTY_FUNCTION__: " << __PRETTY_FUNCTION__ << endl;
}
};
void TestFunction(){
cout << "Output of __func__ is: " << __func__ << endl;
}
main() {
cout << "Output of __FUNCTION__ is: " << __FUNCTION__ << endl;
TestFunction();
MyClass myObj;
myObj.Class_Function();
}输出
Output of __FUNCTION__ is: main Output of __func__ is: TestFunction The result of __PRETTY_FUNCTION__: void MyClass::Class_Function()
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP