分享方式:


編譯器錯誤 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 初始化值。