Can somebody explain to me why the following code compiles
#include <cmath>
class BaseFunctionClass {
public:
virtual double operator()(const double x) const = 0;
virtual ~BaseFunctionClass() {}
};
class mySin : public BaseFunctionClass {
public:
double operator()(double x) const override {
return std::sin(x);
}
};
int main(){
mySin f1;
return 0;
}
We have the two definitions:
double operator()(const double x) const //BaseFunctionClass
double operator()(double x) const //mySin
but shouldn't the override
keyword make sure that I can only redefine functions in derived classes that have a virtual
counterpart in the base class? Why is the const
for the argument ignored?