Say I have three classes, ClassA
, ClassB
, and ClassC
. And all three of these classes have a function called updateValue(int)
.
From your current interface, you might do something like:
class Controller
{
public:
template <class...Classes>
Controller(Classes&... classes)
{
mF = [&](int val) { (classes.updateValue(val), ...); }; // Fold expression from C++17
}
void setValues(int val)
{
mF(val);
}
private:
std::function<void(int)> mF;
};