I'm trying to create a map of strings to functions. When it's a simple function, I've seen how to do this like so:
typedef int (*GetIntFunction)(void);
int get_temp()
{
return 42;
}
map<string, GetIntFunction> get_integer_map { { "temp", &get_temp } };
auto iter = get_integer_map.find("temp");
int val = (*iter->second()();
However, I'd like my function pointer to be to a function of a specific object. And, I know which object I need at map creation. Something like this:
class TemperatureModel
{
public:
int GetTemp();
}
TemperatureModel *tempModel = new TemperatureModel();
map<string, GetIntFunction> get_integer_map { { "temp", &(tempModel->GetTemp} };
If you'd like to know why I'm doing this, I'm trying to read a list of parameters from an input file, get their values from the correct model, and then output their values to an output file. I will also need to set values at runtime using a similar map.