Getting error C3352 (specified function doesn't match delegate type), even though function seems to match delegate type

六月ゝ 毕业季﹏ 提交于 2019-12-09 03:18:08

问题


Here is the exact error message on compilation:

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 is a private function in the reference class MyRefClass

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);

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);

回答1:


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);


来源:https://stackoverflow.com/questions/9808428/getting-error-c3352-specified-function-doesnt-match-delegate-type-even-thoug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!