編譯器錯誤 C2076
以大括弧括住的初始化運算式清單不能用於類型包含 'auto/decltype(auto)' 的新運算式中
auto
如果型別規範出現在新型別識別碼的規範序列或運算式的 new
型別識別碼中,則運算式必須包含格式 ( assignment-expression )
的初始化運算式。 編譯器會從 assignment-expression
初始化運算式中的 推斷型別識別碼。 例如,
new auto(42); // new allocates int
auto c = new auto('a'); // c is of type char*, new allocates char
new (auto*)(static_cast<short*>(nullptr)); // allocates type short*
若要解決此問題,請使用括弧括住運算式的 new
初始化值。
意見反映
https://aka.ms/ContentUserFeedback。
即將推出:我們會在 2024 年淘汰 GitHub 問題,並以全新的意見反應系統取代並作為內容意見反應的渠道。 如需更多資訊,請參閱:提交及檢視以下的意見反映: