gpt4 book ai didi

c++-cli - 出现错误 C3352(指定的函数与委托(delegate)类型不匹配),即使函数似乎与委托(delegate)类型匹配

转载 作者:行者123 更新时间:2023-12-04 10:10:24 27 4
gpt4 key购买 nike

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

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 中的私有(private)函数

当我尝试创建私有(private)委托(delegate) MyDelegate 的实例时,出现引用的错误,在同一个引用类中声明,代码如下:
MyDelegate^ del = gcnew MyDelegate(&MyRefClass::MyFunction);

据我所知,函数的签名 MyFunctionWrapper与委托(delegate)匹配,所以我不确定是什么导致了错误。

为了完整起见,(私有(private))函数签名是:
double MyFunction(const std::vector<double> &x, std::vector<double> &grad, void *data)

并且(私有(private))代表声明是:
delegate double MyDelegate(const std::vector<double> &x, std::vector<double> &grad, void *data);

最佳答案

我没有看到 static 这个词在您的方法签名中。如果方法不是静态的,则需要将对象传递给委托(delegate)构造函数。试试这个:

MyDelegate^ del = gcnew MyDelegate(this, &MyRefClass::MyFunction);

关于c++-cli - 出现错误 C3352(指定的函数与委托(delegate)类型不匹配),即使函数似乎与委托(delegate)类型匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808428/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com