Ok, it’s been a while since I wrote in C++.
and I’ve never done anything quiet this high level.
So basically I need to create a class.
The constructor for the class needs to take a reference (or pointer) to a method form another class, or to a function.
Basically I have a class that needs to on occasion read a value from a fltk valuator (version 1.1.x), and then change some stuff about itself.
Each object will have it’s own valuator associated with it.
(they also have a link to another object of the same parent, which after updating them selves from the valuator will tell to update, and so on)
So how do i pass functions around, in constructors?
Here is an example where a method of
Foois passed to theBarconstructor and later invoked on a givenBarobject:If, on the other hand, you already know the
Fooobject atBarconstruction time, thenBardoes not really care which class the method belongs to. All it needs is a functor to call later, and theFooobject can simply be bound by the client.If you don’t have a C++0x compiler, replace
std::bindwithstd::tr1::bindorboost::bind.