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?
EDIT: setting the keyword static before static int xGetSSE16N( DistParam* pcDtParam )
solved the problem. Can someone explain why? And the question remains with Dev C++ that resolved the problem without static and VS2017 not?
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 \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;
}