显示函数的完全限定名称 [英] Displaying fully qualified name of the function

查看:120
本文介绍了显示函数的完全限定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

输出 myfunction 。很遗憾, __ funct __ 不起作用。如何输出成员函数的完全限定名称 A :: myfunction

解决方案

没有标准定义的方式。但是,如果您使用gcc,您可以使用 __ PRETTY_FUNCTION __ 而不是 __ func __



标准C ++(即C ++ 03)没有 __ func __ __ PRETTY_FUNCTION __ p>

C ++ 0x从C99导出 __ func __ ,它在8.4.2 / 8(n3290)中定义


定义函数局部预定义变量 __ func __ p>

static const char __func __ [] =function-name;


$ b b

,其中function-name是一个实现定义的字符串



#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 ?

解决方案

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

这篇关于显示函数的完全限定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆