G
Gregory L. Hansen
I'm playing with a simulation where different parts of a system, like a
controller or a thermometer or a thermal mass, are represented as classes,
instantiated, and connected together like Tinkertoys. My thought at first
was that each class would have a member function like get_ouput(). When
some object like a thermal mass needs an input, like heat from a control
system, my thought was to add a pointer to that object to an internal
list, like
target.add_heat(&controller);
But I've discovered I want a little more flexibility to choose a member
function as the input. So I'd like to use something analogous to pointers
to regular functions, like
float (*pf)();
pf = controller.get_heat;
target.add_heat(pf);
But I've been playing with variations on that theme and I can't get it to
work.
Can I do this sort of thing in C++?
controller or a thermometer or a thermal mass, are represented as classes,
instantiated, and connected together like Tinkertoys. My thought at first
was that each class would have a member function like get_ouput(). When
some object like a thermal mass needs an input, like heat from a control
system, my thought was to add a pointer to that object to an internal
list, like
target.add_heat(&controller);
But I've discovered I want a little more flexibility to choose a member
function as the input. So I'd like to use something analogous to pointers
to regular functions, like
float (*pf)();
pf = controller.get_heat;
target.add_heat(pf);
But I've been playing with variations on that theme and I can't get it to
work.
Can I do this sort of thing in C++?