I try to do something like
class base {
public:
virtual double operator() (double val) = 0;
virtual double operator() (double prev, double val) {
return prev + operator()(val);
}
};
class derived: public base {
virtual double operator() (double val) {
return someting_clever;
}
};
I want to overload the operator() to use it with different algorithms such as std::accumulate or std::transform. I’m totally happy with the base class definition of operator()(double, double). However I can’t call it from the derived class. Do I have to rewrite the same code for each class I derive from base?
The problem here is that defining a function in a derived class hides the same function in the base class; this is the reason why you cannot access
operator()(double, double)from the derived class.But there is a way to do it: you can just use a
usingdirective in your derived class: