编译器警告(等级 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

以下使用 C++ 示例(使用 Visual Basic 创建的 .dll),

// 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);
}