__func__ C ++ 11函数的本地预定义变量,不会编译 [英] __func__ C++11 function's local predefined variable, won't compile
问题描述
函数的 __ func __
C ++ 11本地预定义变量不会在使用默认内置Visual Studio的Visual Studio 2012 Professional(使用Update 1安装)中编译2012(v110)编译器或2012年11月的CTP(v120_CTP_Nov2012)编译器。但是,编辑不会在 __ func __
下抱怨任何红色的下划线。 __ func __
应该给出其包含函数的名称,在这种情况下为 foo
,但这既不编译也不使编辑器抱怨:
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;
}
这会导致编译器错误:
error C2065: '__func__' : undeclared identifier
我在我的代码中缺少一些东西,或者将来在更新中工作?
Am I missing something in my code or will this work in a future update?
推荐答案
MSVC的C99支持相当差一般;你最好的选择是使用MSVC特定的 __ FUNCTION __
宏。有关详情,请参阅此问题:跨平台定义宏的#define __FUNCTION__和__func__
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__
更新(2015-06-22):Visual Studio 2015支持 __ func __
,请参阅博客
Update (2015-06-22): Visual Studio 2015 supports __func__
, see the blog post
这篇关于__func__ C ++ 11函数的本地预定义变量,不会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!