Using function non-member of class inside this class
Hello, here some problem with using function NOT a member of class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
double function (double (*fun) (double),double a)
{
return (*fun)(a);
}
class SomeClass
{
private:
double x;
public:
double M;
double M_func (double y)
{
return y*y;
}
void set_M()
{
M=function(&M_func,x);
}
}
|
the error - 49:40: error: cannot convert ‘double (SomeClass::*)(double, double)’ to ‘double (*)(double, double)’
i know it`s looks strange to set M like that, but in my real code i have to.
How to make it right?
It does really look weird. What's keeping you from simply doing M = M_func(x);
?
normal functions and member functions are two different things so you can't treat them the same.
Maybe you want to make M_func a static function?
Topic archived. No new replies allowed.