Displaying fully qualified name of the function

2020-07-10 10:53发布

#include <iostream>
class A{
    public:
    void myfunction(){
        std::cout << __func__; 
    }
};
int main(){
    A obj;
    obj.myfunction();
}

Output is myfunction. Unfortunately __funct__ does not work. How to output the fully qualified name of the member function i.e A::myfunction ?

标签: c++ function
2条回答
再贱就再见
2楼-- · 2020-07-10 11:34

There is no standard defined way for the same. However if you are using gcc you can use __PRETTY_FUNCTION__ instead of __func__.

Standard C++ (i.e C++03) does not have either __func__ or __PRETTY_FUNCTION__.

C++0x derives __func__ from C99 and it is defined in 8.4.2/8 (n3290)

The function-local predefined variable __func__ is defined as if a definition of the form

static const char __func__[] = "function-name ";

had been provided, where function-name is an implementation-defined string

查看更多
做自己的国王
3楼-- · 2020-07-10 11:47

As @Prasoon says, there's no standard way.
For Visual Studio, __FUNCTION__ displays the fully qualified name.

查看更多
登录 后发表回答