3

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

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

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

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

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

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

4

1 回答 1

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 的程序是格式错误的。

于 2010-05-17T09:05:44.350 回答