【问题标题】:Getting error C3352 (specified function doesn't match delegate type), even though function seems to match delegate type出现错误 C3352(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配
【发布时间】:2012-03-21 16:06:47
【问题描述】:

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

error C3352: 'double MyNamespace::MyRefClass::MyFunction(const std::vector<_ty> &,std::vector<_ty> &,void *)' : 指定的函数不匹配委托类型'double (const std::vector<_ty> &,std::vector<_ty> &,void *)'

MyFunction是引用类MyRefClass中的私有函数

当我尝试创建私有委托MyDelegate 的实例时出现引用错误,该实例在同一引用类中声明,代码如下:

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

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

为了完整起见,(私有)函数签名是:

double MyFunction(const std::vector<double> &x, std::vector<double> &grad, void *data)

并且(私有)委托声明是:

delegate double MyDelegate(const std::vector<double> &x, std::vector<double> &grad, void *data);

【问题讨论】:

    标签: c++-cli


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-12-17
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      相关资源
      最近更新 更多