I'm trying to join an old piece of code in C to my present VC++ project:
// .h
class DMSinv : public CDialog {
double finte(double z);
double ITFStolz(double Zp1, double Zp2, double Zc);
};
// .cpp
double Zcglob;
double DMSinv::finte(double z)
{
return TFStolz(z, Zcglob);
}
double DMSinv::ITFStolz(double Zp1, double Zp2, double Zc)
{
int ierr;
Zcglob = Zc;
return (coteglob(&DMSinv::finte, Zp1, Zp2, 1.0e-10, &ierr));
//error C2664: 'DMSinv::coteglob' : cannot convert parameter 1 from 'double (__thiscall DMSinv::* )(double)' to 'double (__cdecl *)(double)'
}
the coteglob function comes from the old C part, and finte is a intermediate function to pass the TFStolz function to coteglob.
I've searched in the forums and found this related question: How to convert void (__thiscall MyClass::* )(void *) to void (__cdecl *)(void *) pointer which I tried to apply in this way:
// .h
class DMSinv : public CDialog {
virtual double finte(double z);
double ITFStolz(double Zp1, double Zp2, double Zc);
};
// .cpp
double Zcglob;
extern "C"
{
static double __cdecl finteHelper(double z)
{
DMSinv* datainv = reinterpret_cast< DMSinv > (z); //error C2440: 'reinterpret_cast' : cannot convert from 'double' to 'DMSinv'
datainv->finte(z);
}
}
double DMSinv::ITFStolz(double Zp1, double Zp2, double Zc)
{
int ierr;
Zcglob = Zc;
double solution = coteglob(&finteHelper, Zp1, Zp2, 1.0e-10, &ierr);
return solution;
}
but is still not working. Can somebody guide me on how to adapt it? I'm quite a newbie yet and this seems far from my knowledge.
Thanks in advance!