title: Dynamic proxy classes in C++. Is it possible?
body: <p>First of all, let me say that I'm not a guru C++ programmer. I have a few years of experience in C++, but my main area is .NET/C#. </p>
  
  <p>I'm looking into a way to create dynamic proxy/wrapper classes in C++. Particularly, what I want to achieve is to intercept a method call. This kind of tricks is common in Java/.NET world, but C++ lacks Reflection. </p>
  
  <p>I found an <a href="http://cppguru.wordpress.com/2009/01/14/c-proxy-template/" rel="nofollow">online tutorial</a>, which explains how to create a wrapper and intercept method calls through -> operator overloading:</p>
  
  <pre><code>class Person{
    std::string mName;
    Person(std::string pName): mName(name){}
    void printName(){
       std::cout &lt;&lt; mName &lt;&lt; std::endl;
    }
  
  };
  
  template &lt;class T &gt;
  class Wrap {
       T * p ;
       public:
               Wrap (T * pp ) :p (pp) { }
               Call_proxy &lt;T&gt; operator -&gt;() {
                     prefix ();
                     return Call_proxy&lt;T&gt;(p);
               }
  };
  template &lt;class T &gt;
  class Call_proxy {
         T * p ;
         public :
                Call_proxy (T * pp ) :p (pp ){ }
                ˜Call_proxy () {
                       suffix ();
                 }
                 T * operator -&gt;() {
                            return p ;
                  }
   };
  </code></pre>
  
  <p>As you can see from this sample, we can catch method calls events, before and after call, but what is not clear for me, is how to detect which method is being called? Is it possible at all?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Allright, to make things more clear, I don't really care if the implementation would be truly dynamic or not. Having a wrapper class similar to smart pointers is fine for me.</p>