編譯器錯誤 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;
}