在VC++ 11中使用别名声明

Mar*_*een 7 c++ visual-c++ c++11

以下代码示例使用别名声明C++ 11中的new无法使用VC++ 11进行编译,VS2012中的更新1并发出包含的错误.它在Windows 7上的MinGW下使用GCC 4.7.2进行编译和执行g++ -std=c++11 -Wall in.cpp.

我没有发现任何迹象表明这不受支持.此外,IntelliSense不会发现任何错误,并显示cdptr类型所示的工具提示typedef const double *cdptr.我的项目设置为使用v110平台工具集并编译为C++代码.

我如何冤枉微软?

#include <iostream>

int main()
{
    using cdptr = const double*;

    const double pi = 3.14159;
    cdptr cdp = &pi;

    std::cout << "cdp: " << (*cdp) << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

构建输出:

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 ==========
Run Code Online (Sandbox Code Playgroud)

K-b*_*llo 11

MSVC11,即使使用11月CTP,也没有使用别名声明.

您可以在此处找到C++ 11支持表.

  • @MartinshShaiters:是的,整件事。公平地说,该功能的全部动机是模板部分,因此任何编译器都不太可能在没有的情况下实现它(这只是 typedef)。 (2认同)

Yuu*_*shi 5

基于,Visual Studio 2012似乎还不支持类型别名.