出现错误C3352(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配 [英] Getting error C3352 (specified function doesn't match delegate type), even though function seems to match delegate type

查看:188
本文介绍了出现错误C3352(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是编译时的确切错误消息:

Here is the exact error message on compilation:


错误C3352:'double MyNamespace :: MyRefClass :: MyFunction(const std :: vector< _Ty>&,std :: vector< _Ty>&,void *)':指定的函数与委托类型'double(const std :: vector< _Ty> &,std :: vector< _Ty>&,void *)'

error C3352: 'double MyNamespace::MyRefClass::MyFunction(const std::vector<_Ty> &,std::vector<_Ty> &,void *)' : the specified function does not match the delegate type 'double (const std::vector<_Ty> &,std::vector<_Ty> &,void *)'

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(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆