P
Patrick Guio
Dear all,
I cannot figure out why I cannot have the operator() member function
declared const?
This operation shouldn't modify anything in my class...
Sincerely,
Patrick
#include <map>
class functions
{
public:
functions() {
funs[1] = &functions::f1;
}
// cannot compile with operator() declared const.
// double operator()(double x) const { return (this->*funs[1])(x); }
double operator()(double x) { return (this->*funs[1])(x); }
protected:
typedef std::map<int, double (functions::*)(double) const> FunctionsMap;
FunctionsMap funs;
double f1(double x) const { return x*x; }
};
I cannot figure out why I cannot have the operator() member function
declared const?
This operation shouldn't modify anything in my class...
Sincerely,
Patrick
#include <map>
class functions
{
public:
functions() {
funs[1] = &functions::f1;
}
// cannot compile with operator() declared const.
// double operator()(double x) const { return (this->*funs[1])(x); }
double operator()(double x) { return (this->*funs[1])(x); }
protected:
typedef std::map<int, double (functions::*)(double) const> FunctionsMap;
FunctionsMap funs;
double f1(double x) const { return x*x; }
};