编译器错误 C3538
在声明符列表中,“auto”必须始终推导为同一类型
声明列表中的所有声明变量不能解析为同一类型。
更正此错误
- 确保该列表中的所有 auto 声明都推导为同一类型。
示例
下面的语句会产生 C3538。 每个语句都声明多个变量,但每个语句所使用的 auto 关键字不能推导为同一类型。
// C3538.cpp
// Compile with /Zc:auto
// C3538 expected
int main()
{
// Variable x1 is a pointer to char, but y1 is a double.
auto * x1 = "a", y1 = 3.14;
// Variable c is a char, but c1, c2, and c3 are pointers to pointers.
auto c = 'a', *c1 = &c, * c2 = &c1, * c3 = &c2;
// Variable x2 is an int, but y2 is a double and z is a char.
auto x2(1), y2(0.0), z = 'a';
// Variable a is a pointer to int, but b is a pointer to double.
auto *a = new auto(1), *b = new auto(2.0);
return 0;
}