VS2017 assignment operator to a function address returns error C2276

  c++, memory-address

The code compiles & runs just fine using Dev C++ but under VS2017 I get error C2276 at Get::Init(). I am a little bit surprised because this code was taken and isolated from the code https://hevc.hhi.fraunhofer.de/HM-doc/_t_com_rd_cost_8cpp_source.html at line 126 Void TComRdCost::init() that compiles just fine under VS2017. Where am I wrong here? What am I missing?

error C2276 ‘&’: illegal operation on bound member function expression"

#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 nn";       
        return 1000;    
    }   
    init() {        
        m_afpDistortFunc[0] = (FpDistFunc) (&xGetSSE16N);
    }
    SetDistFunc(DistParam *p) {     
        p->CustomFunction = m_afpDistortFunc[0];        
    }   
};



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

Source: Windows Questions C++

LEAVE A COMMENT