#include class Foo { public: int x; float y; template void apply_to_members(Fn& fn) { fn(x, y); } }; template struct Bar { Fn& fn; Bar(Fn& fn) : fn(fn) {} void operator()() { } template void operator()(const T& t, Params... params) { fn(t); (*this)(params...); } }; struct Baz { template void operator()(const T& t) { std::cout << t << std::endl; } }; int main() { Foo f = { 3, 4.9 }; Baz z; Bar b(z); f.apply_to_members(b); };