`auto int i`是否有效C++ 0x?

Mot*_*tti 3 c++ standards-compliance c++11

在回答这个问题时,问题是关键字(自动存储)的传统C含义autoC++ 0x中是否仍然有效,现在它意味着类型推导.

我记得,旧的含义auto应该保留在相关的地方,但其他人不同意.

auto char c = 42; // either compilation error or c = '*'
Run Code Online (Sandbox Code Playgroud)

看看编译器,我看到了当前的部门.

  1. 不再允许auto的旧含义
    • VS10
    • 克++
  2. 在相关时使用auto的旧含义

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

GMa*_*ckG 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
Run Code Online (Sandbox Code Playgroud)

如您所见,它会导致错误.§7.1.6.5相当于以下事项:

在本节未明确允许的上下文中使用auto的程序是不正确的.

  • @Pavel:我几乎不称它为无用或破坏.在当天的C或C++代码中,您经常发现`auto`**? (8认同)
  • 它没有打破真正的程序,它使语言更容易理解.汽车的旧意义毫无用处. (6认同)
  • 事实上,任何破碎的计划都应该被打破.旧的用法比无用的更糟糕; 这是误导. (3认同)