First of all, let me say that I am not a C ++ programmer. I have several years of experience in C ++, but my main area is.NET/C#.
I am looking for a way to create dynamic proxy / wrapper classes in C ++. In particular, I want to achieve interception of a method call. Such tricks are common in the Java / .NET world, but in C ++ there is no Reflection.
I found an online tutorial that explains how to create shell calls and intercept through β operator overloading:
class Person{ std::string mName; Person(std::string pName): mName(name){} void printName(){ std::cout << mName << std::endl; } }; template <class T > class Wrap { T * p ; public: Wrap (T * pp ) :p (pp) { } Call_proxy <T> operator ->() { prefix (); return Call_proxy<T>(p); } }; template <class T > class Call_proxy { T * p ; public : Call_proxy (T * pp ) :p (pp ){ } ΛCall_proxy () { suffix (); } T * operator ->() { return p ; } };
As you can see from this example, we can catch method calls before and after the call, but it is not clear to me how to determine which method is being called? Is it possible at all?
thanks
UPDATE
Well, to make things clearer, I don't care if the implementation is really dynamic or not. Having a wrapper class like smart pointers is right for me.
source share