问题描述
以下是编译时的确切错误消息:
Here is the exact error message on compilation:
MyFunction
是引用类 MyRefClass
中的私有函数创建在同一引用类中声明的私有委托 MyDelegate
的实例,其代码为:
The quoted error shows up when I try to create an instance of the private delegate MyDelegate
, declared in the same reference class, with the code:
MyDelegate^ del = gcnew MyDelegate(&MyRefClass::MyFunction);
据我所知,函数 MyFunctionWrapper的签名
与委托匹配,所以我不确定是什么引起了错误。
As far as I can tell, the signatures of the function MyFunctionWrapper
matches the delegate, so I'm not sure what is causing the error.
为了完整起见,(私有)函数签名是:
For completeness, the (private) function signature is:
double MyFunction(const std::vector<double> &x, std::vector<double> &grad, void *data)
,(私有)委托人声明为:
and the (private) delegate declaration is:
delegate double MyDelegate(const std::vector<double> &x, std::vector<double> &grad, void *data);
推荐答案
我看不到<$ c $方法签名中的c> static 。如果方法不是静态的,则需要将对象传递给委托构造函数。尝试以下操作:
I don't see the word static
in your method signature. If the method isn't static, you need to pass the object to the delegate constructor. Try this:
MyDelegate^ del = gcnew MyDelegate(this, &MyRefClass::MyFunction);
这篇关于出现错误C3352(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!