代码之家  ›  专栏  ›  技术社区  ›  Motti

“自动int i”有效C++ +0x吗?

  •  3
  • Motti  · 技术社区  · 15 年前

    在回答中 this question 问题是传统的 C 关键字的含义 auto C++ 0x 现在它意味着类型演绎。

    应该留在相关的地方,但其他人不同意。

    auto char c = 42; // either compilation error or c = '*'
    

    看看编译器,我看到了当前的划分。

    1. 汽车的旧含义已不再被允许
      • VS10型
      • 克++

    你知道哪种行为是正确的吗?

    1 回复  |  直到 8 年前
        1
  •  15
  •   GManNickG    15 年前

    不,不是。事实上,§7.1.6.4/3给出了以下示例:

    auto x = 5; // OK: x has type int
    const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int
    static auto y = 0.0; // OK: y has type double
    auto int r; // error: auto is not a storage-class-specifier
    

    如您所见,它会导致一个错误。§7.1.6.5基本上决定了交易:

    在本节中不明确允许的上下文中使用auto的程序是格式错误的。