构建使用强类型数据集的 C++CLI 项目时出现警告 C4564
升级到 VC++ 2010 后,在构建使用 C# 项目中的强类型数据集的 C++/CLI 项目时,会引发警告 C4564(方法定义了不受支持的默认参数)。
ReadersManager.cpp(311):警告 C4564:“System::Data::DataTable”类的方法“SetNewRecord”定义了不支持的默认参数“action”
调用方法时显式指定值“2”
从程序集“System.Data,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”导入类型“System::Data::DataTable”时发生此诊断。
从程序集“System.Data.DataSetExtensions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”导入类型“System::Data::TypedTableBase”时发生此诊断。
从程序集“MyProductDataStoreCLR,Version=4.5.0.9,Culture=neutral,PublicKeyToken=null”导入类型“MyProductDataStoreCLR::ReadersDataSet::ReadersDataTable”时发生此诊断。
警告是在调用 System::Data::DataTable::Select
时引发的,因此我无法更改与 SetNewRecord
相关的调用代码。
这是 C++/CLI 不支持新的 C# 可选参数功能的问题吗?
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'
Specify value '2' explicitly when calling the method
This diagnostic occurred while importing type 'System::Data::DataTable ' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
This diagnostic occurred while importing type 'System::Data::TypedTableBase ' from assembly 'System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一条 4 级警告消息,属于“有一天这可能会在后端对您造成影响”类别。在 .NET 语言中,对使用默认参数值调用方法而不指定该值的支持很不稳定。 VB.NET 一直拥有它,C# 只是在版本 4 中获得了它。C++/CLI 不支持它,而且肯定永远不会支持它。值得注意的是,C++ 语言确实支持它。 C++/CLI 程序员很可能对此感到惊讶,因此会出现警告。
对于该警告,您无能为力,数据集的代码是自动生成的。否则它是完全良性的,如果您调用该方法而不为具有默认值的参数提供值,那么您将收到编译器错误。
只需使用
#pragma warning(disable:4564)
或 Project > 关闭警告即可。属性> C/C++>高级> “禁用特定警告”设置。It is a warning level 4 message, falling in the category "this may byte you in the rear end 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" setting.