문제

The __func__ C++11 local predefined variable of a function does not compile in Visual Studio 2012 Professional (with Update 1 installed) with the default built-in Visual Studio 2012 (v110) compiler or the November 2012 CTP (v120_CTP_Nov2012) compiler. However, the editor does not complain with any red squiggly underline under __func__. __func__ is supposed to give the name of its containing function, in this case foo, but this neither compiles nor make the editor complain:

#include <iostream>
using namespace std;

void foo()
{
    cout << __func__ << endl;
    return;
}

int main()
{
    foo();
    return 0;
}

It gives the compiler error:

error C2065: '__func__' : undeclared identifier

Am I missing something in my code or will this work in a future update?

도움이 되었습니까?

해결책

MSVC's C99 support is quite poor in general; your best bet might be to use the MSVC-specific __FUNCTION__ macro. See this question for details: Cross-platform defining #define for macros __FUNCTION__ and __func__

Update (2015-06-22): Visual Studio 2015 supports __func__, see the blog post

다른 팁

Compile the program using C++11 standards as __func__ is C++11 feature.

So, compile it like:

g++ -std=c++11 foo.cpp -o foo
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top