pointer to virtual function
-
Hi all, this is the error I'm getting: "error C2276: '&' : illegal operation on bound member function expression", Apparently, this is due to assigning a pointer to a virtual function, yet I do not have any function declared virtual. Does any one know a way around this problem? Is there a way to force a function not to be virtual? Here's a snippet of my code: In .h … class MyClass {… int VBGCalc(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); int VBGPartials(const gsl_vector *x, void *params, gsl_matrix *J); int VBGFunct(const gsl_vector *x, void *params, gsl_vector *f); int VBGF(void); //problem in this function … }; in .cpp int MyClass::VBGF(void) … f.f = &VBGFunct; //offending code f.df = &VBGPartials; //ditto f.fdf = &VBGCalc; //ditto … return 1; } int (* f) (const gsl_vector * x, void * params, gsl_vector * f); gsl_vector and gsl_matrix are struct variables. Thanks, Ralf. ralf.riedel@usm.edu
-
Hi all, this is the error I'm getting: "error C2276: '&' : illegal operation on bound member function expression", Apparently, this is due to assigning a pointer to a virtual function, yet I do not have any function declared virtual. Does any one know a way around this problem? Is there a way to force a function not to be virtual? Here's a snippet of my code: In .h … class MyClass {… int VBGCalc(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); int VBGPartials(const gsl_vector *x, void *params, gsl_matrix *J); int VBGFunct(const gsl_vector *x, void *params, gsl_vector *f); int VBGF(void); //problem in this function … }; in .cpp int MyClass::VBGF(void) … f.f = &VBGFunct; //offending code f.df = &VBGPartials; //ditto f.fdf = &VBGCalc; //ditto … return 1; } int (* f) (const gsl_vector * x, void * params, gsl_vector * f); gsl_vector and gsl_matrix are struct variables. Thanks, Ralf. ralf.riedel@usm.edu
You can't assign a member function pointer to an ordinary function pointer. The type of
VBGFunct
isint (MyClass::*) (const gsl_vector *, void *, gsl_vector *)
. You can't take the address of a member function pointer. You would have to either declaref
asint (MyClass::*f)( /*etc*/ )
or declare your functions asstatic
. If you do the first, you must call them using the ->* or .* notation, e.g.:(this->*f)(pX, pParams, pF)
If you do the second, you won't be able to access any non-static members of
MyClass
. If you're trying to provide polymorphism, it's easier to either do run-time polymorphism via inheritance, or compile-time polymorphism using templates. Stability. What an interesting concept. -- Chris Maunder -
Hi all, this is the error I'm getting: "error C2276: '&' : illegal operation on bound member function expression", Apparently, this is due to assigning a pointer to a virtual function, yet I do not have any function declared virtual. Does any one know a way around this problem? Is there a way to force a function not to be virtual? Here's a snippet of my code: In .h … class MyClass {… int VBGCalc(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); int VBGPartials(const gsl_vector *x, void *params, gsl_matrix *J); int VBGFunct(const gsl_vector *x, void *params, gsl_vector *f); int VBGF(void); //problem in this function … }; in .cpp int MyClass::VBGF(void) … f.f = &VBGFunct; //offending code f.df = &VBGPartials; //ditto f.fdf = &VBGCalc; //ditto … return 1; } int (* f) (const gsl_vector * x, void * params, gsl_vector * f); gsl_vector and gsl_matrix are struct variables. Thanks, Ralf. ralf.riedel@usm.edu
member functions are of __THISCALL so i guess assigning a pointer to the method could of some problem and also using it.. try making the methods static i guess then it will work... But then i dont know wheather making them static is in ur software design.
MSN Messenger. prakashnadar@msn.com "If history isn't good, just burn it." - Sidhuism.
-
member functions are of __THISCALL so i guess assigning a pointer to the method could of some problem and also using it.. try making the methods static i guess then it will work... But then i dont know wheather making them static is in ur software design.
MSN Messenger. prakashnadar@msn.com "If history isn't good, just burn it." - Sidhuism.
Made it static. Much easier. Thank you all, Ralf. ralf.riedel@usm.edu