分享方式:


編譯器錯誤 C2073

'identifier' :部分初始化陣列的專案必須有預設建構函式

備註

使用者定義型別或常數陣列指定的初始化運算式太少。 如果未為數組成員指定明確的初始化運算式及其對應的建構函式,則必須提供預設建構函式。

在 Visual Studio 2022 中,這個編譯器錯誤已經過時。

範例

下列範例會產生 C2073。 原始程式檔 C2073.cpp

// C2073.cpp
class A {
public:
   A( int );   // constructor for ints only
};
A a[3] = { A(1), A(2) };   // C2073, no default constructor

原始程式檔 C2073b.cpp 中會顯示修正程式:

// C2073b.cpp
// compile with: /c
class B {
public:
   B();   // default constructor declared
   B( int );
};
B b[3] = { B(1), B(2) };   // OK