編譯器警告 (層級 3) C4534
'constructor' 不會是類別 'class' 的預設建構函式,因為預設自變數
Unmanaged 類別可以具有具有預設值的參數建構函式,編譯程式會使用此建構函式做為預設建構函式。 以 關鍵詞標示的 value
類別不會使用具有其參數預設值的建構函式做為預設建構函式。
如需詳細資訊,請參閱類別與結構。
下列範例會產生 C4534:
// C4534.cpp
// compile with: /W3 /clr /WX
value class MyClass {
public:
int ii;
MyClass(int i = 9) { // C4534, will not be the default constructor
i++;
}
};
int main() {
MyClass ^ xx = gcnew MyClass;
xx->ii = 0;
}