views:

65

answers:

1

After upgrade to VC++ 2010, Warning C4564 is raised (method defines unsupported default parameter) when building a C++/CLI project that consumes a strong-typed dataset from a C# project.

ReadersManager.cpp(311): warning C4564: method 'SetNewRecord' of class 'System::Data::DataTable' defines unsupported default parameter 'action'

3>          Specify value '2' explicitly when calling the method
3>          This diagnostic occurred while importing type 'System::Data::DataTable ' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
3>          This diagnostic occurred while importing type 'System::Data::TypedTableBase ' from assembly 'System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
3>          This diagnostic occurred while importing type 'MyProductDataStoreCLR::ReadersDataSet::ReadersDataTable ' from assembly 'MyProductDataStoreCLR, Version=4.5.0.9, Culture=neutral, PublicKeyToken=null'.

The warning is being raised on a call to System::Data::DataTable::Select, so there is nothing I can change in the calling code relevant to SetNewRecord.

Is this an issue of C++/CLI not supporting the new C# optional parameters capability?

+1  A: 

It is a warning level 4 message, falling in the category "this may byte you in the ass some day". Support for calling methods with default parameter values without specifying the value is spotty in the .NET languages. VB.NET always had it, C# just acquired it in version 4. C++/CLI does not support it and surely never will. Which is notable because the C++ language does support it. A C++/CLI programmer could well be surprised by this, thus the warning.

There isn't much you can do about the warning, the code for the dataset is auto-generated. It is otherwise utterly benign, if you call the method without supplying a value for the argument with the default value then you'll get a compiler error.

Just turn the warning off with #pragma warning(disable:4564) or Project + Properties, C/C++, Advanced, Disable Specific Warnings.

Hans Passant

related questions