微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VS2017 对函数地址的赋值运算符返回错误 C2276

如何解决VS2017 对函数地址的赋值运算符返回错误 C2276

代码使用 Dev C++ 编译并运行得很好,但在 VS2017 下,我在 Get::Init() 处收到错误 C2276。我有点惊讶,因为这段代码是从第 126 行 Void TComrdcost::init() 处的代码 https://hevc.hhi.fraunhofer.de/HM-doc/_t_com_rd_cost_8cpp_source.html提取的,它在 VS2017 下编译得很好。我哪里错了?我错过了什么?

编辑:在 static int xGetSSE16N( distParam* pcDtParam ) 解决问题之前设置 keyword 静态。有人可以解释为什么吗?问题仍然存在于 Dev C++ 中,它在没有 static 和 VS2017 的情况下解决了问题?

错误 C2276 '&': 对绑定成员函数表达式的非法操作"

#include <iostream>
using namespace std;

class distParam;


typedef int (*FpdistFunc) (distParam*); // int FpdistFunc(distParam*)

class distParam {
public:
    FpdistFunc CustomFunction; 
};

class Get {
public:     
    FpdistFunc m_afpdistortFunc[2];
    
    int xGetSSE16N( distParam* pcDtParam ) {        
        std::cout << "xGetSSE16N is called \n\n";       
        return 1000;    
    }   
    void init() {       
        m_afpdistortFunc[0] = (FpdistFunc) (&xGetSSE16N);
    }
    void SetdistFunc(distParam *p) {        
        p->CustomFunction = m_afpdistortFunc[0];        
    }   
};



int main() {
    
    distParam m_cdistParam;
    Get a;
    
    a.init();
    a.SetdistFunc(&m_cdistParam);

    //execute the custom function
    int uiSad = m_cdistParam.CustomFunction( &m_cdistParam );
    
    std::cout << "uiSAD =" << uiSad;

    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。