I know that I already answered, but here itβs different. The better thing is that it is faster (without boost :: function overhead) and avoids binders (since people seem to have an aversion to them), but worse is that it is much less general (since it only works for functions with one argument).
template <typename P, typename T, typename A> A magic(P p, void (T::*f)(A &)) { A a; ((*p).*f)(a); return a; }
What would you call so:
long output_width = magic(raster_props_object, &IRasterProps::get_Width);
Or, if you use GCC, we can use some more tricks:
#define MORE_MAGIC(p,f) ({ \ typedef __typeof(*(p)) big_ugly_identifier; \ magic((p),(&big_ugly_identifier::f)); \ })
What will allow us to do this:
long output_width = MORE_MAGIC(raster_props_object, get_Width);
(Reward points if naming conventions made you think of PDP-10.)
EDIT : updated to use any type of pointer, so now it will work with shared_ptr, iterators and hopefully _com_ptr.
EDIT . Unfortunately, these are pointers, not links. Here's the version (or overload) that is relevant to this, and allows - ignoring - arbitrarily typed return values.
template <typename P, typename T, typename A, typename R> A magic(P p, R (T::*f)(A *)) { A a; ((*p).*f)(&a); return a; }