且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在调试字符串的函数中获取函数名称?

更新时间:2023-11-15 14:16:22

__ FUNCTION __ 由MSVC和GCC支持,并应为您提供所需的信息。


I want to output the function name each time it is called, I can easily copy and paste the function name, however I wondered if there was a shortcut that would do the job for me?

At the moment I am doing:

SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream & in)
{
    qDebug("lynxThreeFile::readSlideInfoHeader");
}

but what I want is something generic:

SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream & in)
{
    qDebug(this.className() + "::" + this.functionName());
}

"__FUNCTION__" is supported by both MSVC and GCC and should give you the information you need.