I have functions in a superclass designed to associate a string with internal functions:
class Base
{
typedef std::function<void(double)> double_v;
bool registerInput(std::string const& key, double_v const& input) {
functions[key] = input;
}
void setInput(std::string key, double value) {
auto fit = functions.find(key);
if (fit == functions.end()) return;
fit->second(value);
}
std::map<std::string, double_v> functions;
}
The idea being that any subclass I can register functions can call them with a string and value:
SubBase::SubBase() : Base(){
Base::registerInput(
"Height",
static_cast<void (*)(double)>(&SubBase::setHeight)
);
}
void SubBase::setHeight(double h) {
....
}
Which could then be called with:
subBaseInstance.setInput("Height", 2.0);
However when I compile I'm getting the following error:
In constructor ‘SubBase::SubBase()’
error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘void (*)(double)’
What am I missing?