samedi 4 mai 2019

Cannot convert pointer to member function to type pointer to function

I'm trying to do something like this:

struct A
{int(*Law)(int, double);
 A(int(*L)(int, double) = LawNULL) : Law(L) {}
 };

struct B : public A
{int funct(int, double) {return 1;}
 B() : A(funct) {}
};

The problem comes in the line

B() : Law(funct) {}

as i get the error "error: invalid use of non-static member function 'int B::funct(int, double)". I've also tried to change the class B as following

struct B : public A
{int funct(int, double) {return 1;}
 B() : A(LawNULL) {Law = funct;}
};

but this produces the error "cannot convert 'B::funct' from type 'int (B::)(int, double)' to type 'int (*)(int, double)'". Is there a way to solve this problem? Thank you in advance for your time

Aucun commentaire:

Enregistrer un commentaire