下面的代码示例使用C++11中的别名声明new无法使用VC++ 11、VS2012中的更新1进行编译,并发出包含的错误。它使用g++ -std=c++11 -Wall in.cpp在Windows7上的MinGW下编译和执行,而不会被GCC 4.7.2偷看。
我没有发现任何迹象表明这是不支持的。此外,IntelliSense不会拾取任何错误,并显示cdptr类型的工具提示,提示为typedef const double *cdptr。我的项目设置为使用v110平台工具集并编译为C++代码。
我怎么得罪了微软?
#include <iostream>
int main()
{
using cdptr = const double*;
const double pi = 3.14159;
cdptr cdp = π
std::cout << "cdp: " << (*cdp) << std::endl;
return 0;
}构建输出:
1>------ Build started: Project: AliasDeclTest, Configuration: Debug Win32 ------
1> AliasDeclTest.cpp
1>f:\aliasdecltest\aliasdecltest.cpp(9): error C2143: syntax error : missing ';' before '='
1>f:\aliasdecltest\aliasdecltest.cpp(9): error C2873: 'cdptr' : symbol cannot be used in a using-declaration
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2065: 'cdptr' : undeclared identifier
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2146: syntax error : missing ';' before identifier 'cdp'
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2065: 'cdp' : undeclared identifier
1>f:\aliasdecltest\aliasdecltest.cpp(14): error C2065: 'cdp' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========发布于 2013-01-09 07:29:41
即使在11月份的CTP中,MSVC11也不会使用别名声明来实现。
您可以找到C++11 support here的表。
发布于 2013-01-09 07:32:09
基于this,Visual Studio2012似乎还不支持类型别名。
https://stackoverflow.com/questions/14225846
复制相似问题