c++/cli 中的委托方差
我正在将工作 C# 代码转换为 C++/CLI,但我无法理解它为何无法编译。
我收到的错误:
void MyNamespace::Handler::DataChanged(System::Object ^,System::EventArgs ^)':指定的函数与委托类型'void (System::Object ^,System ::Data::DataRowChangeEventArgs ^)'
I am in the process of converting working C# code into C++/CLI, and I'm having trouble understanding why it does not compile.
The error I received:
void MyNamespace::Handler::DataChanged(System::Object ^,System::EventArgs ^)' : the specified function does not match the delegate type 'void (System::Object ^,System::Data::DataRowChangeEventArgs ^)'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来 C++/CLI 不像 C# 和 VB 那样支持委托的参数变化,请参阅 此 Microsoft connect 错误报告。
作为解决方法,您可以将对处理程序的调用包装在一个包装器中,该包装器采用 DataRowChangeEventArgs 并调用您的处理程序:
Looks like C++/CLI doesn't support parameter variance for delegates as C# and VB do, see this Microsoft connect bug report.
As a work around your can wrap your call to handler in a wrapper that takes a DataRowChangeEventArgs and calls your handler:
这是该错误的完整可编译再现(可能是注释,但格式会很糟糕):
Here is a complete compile-ready reproduction of the bug (would be a comment, but the formatting would be horrid):