I have a parent class that looks something like this:
class Parent
{
Parent(std::function<double(double)> func);
};
and a derived class that looks something like this:
class Derived : public Parent
{
const double val;
double MyFunc(double x)
{
return x / val;
}
Derived(double value)
: Parent(std::function<double(double)>(&Derived::MyFunc)),
val(value)
{
}
};
Basically, I want to restrict func
from the parent class in a derived class. I know why what I've done above doesn't work; I've tried various other things like making MyFunc
static
; however, this doesn't help because then I can't use value
, which again, makes sense...
Is there a good way to make this work?
Thank you.