Thanks to the unusual properties of operator ->, we can inject code before any member access, at the expense of a slightly bent syntax:
// Nothing special in Foo
struct Foo {
void a() { }
void b() { }
void c() { }
};
struct LoggingFoo : private Foo {
void log() const { }
// Here comes the trick
Foo const *operator -> () const { log(); return this; }
Foo *operator -> () { log(); return this; }
};
Usage looks as follows:
LoggingFoo f;
f->a();
See it live on Coliru