分享方式:


編譯器警告 (層級 4) C4564

類別 'class' 的方法 'method' 定義不支援的預設參數 'parameter'

編譯器偵測到具有預設值的一或多個參數的方法。 叫用 方法時,將會忽略參數的預設值。。明確指定這些參數的值。 如果您未明確指定這些參數的值,C++ 編譯器將會產生錯誤。

假設使用 Visual Basic 建立的下列 .dll,其允許方法引數上的預設參數:

' C4564.vb
' compile with: vbc /t:library C4564.vb
Public class TestClass
   Public Sub MyMethod (a as Integer, _
                        Optional c as Integer=1)
   End Sub
End class

以及下列使用以 Visual Basic 建立的 .dll 的 C++ 範例,

// C4564.cpp
// compile with: /clr /W4 /WX
#using <C4564.dll>

int main() {
   TestClass ^ myx = gcnew TestClass();   // C4564
   myx->MyMethod(9);
   // try the following line instead, to avoid an error
   // myx->MyMethod(9, 1);
}