Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++-cli

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);
like image 699
Rory Avatar asked Mar 21 '12 16:03

Rory


1 Answers

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);
like image 82
David Yaw Avatar answered Sep 18 '22 18:09

David Yaw