【问题标题】:Using alias declaration with VC++ 11在 VC++ 11 中使用别名声明
【发布时间】:2013-01-08 23:28:13
【问题描述】:

以下代码示例使用 C++11 中的新别名声明无法使用 VC++ 11 编译,在 VS2012 中更新 1 并发出包含的错误。它在 Windows 7 上的 MinGW 下使用 g++ -std=c++11 -Wall in.cpp 编译和执行,无需窥视 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 = &pi;

    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 ==========

【问题讨论】:

  • 很确定 VC++11 不支持使用别名声明。

标签: c++ visual-c++ c++11


【解决方案1】:

MSVC11,即使使用 November CTP,也使用别名声明实现。

你可以找到一张C++11支持here的表格。

【讨论】:

  • 我的阅读使我相信它是不支持的 template 别名(参数化类型别名),而不是 N2258 中的所有内容。但是,如果正确的解读是该文档中的所有内容均不受 MSVC11 支持,那么问题就解决了。
  • @MartinshShaiters:是的,整件事。公平地说,该功能的全部动机是模板部分,因此任何编译器都不太可能在没有它的情况下实现它(那只是 typedef)。
  • @GManNickG 是的。但对于 typdef 来说,这是一个非常简洁的语法! :)
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多