title: Customised virtual function
body: <p>I have to design a library using C++ and following are my requirements.</p>
  
  <ol>
  <li>Users should be able to extend my API class methods </li>
  <li>User implemented virtual methods will be called inside of the library polymorphically</li>
  <li>I have to put two log entries before and after each virtual method call</li>
  <li>When user creates his/her own classes and virtual methods, AND if he/she uses my library (has a link to), in addition to normal dynamic binding, above point 3 (having two log entries) should be satisfied</li>
  </ol>
  
  <p>The idea could be sketched out like this?</p>
  
  <pre><code>class BaseClass
  {
  public:
      virtual void foo() = 0;
  };
  </code></pre>
  
  <p>User implementation would be like</p>
  
  <pre><code>class DerivedClass: public BaseClass
  {
  public:
      virtual void foo() {/*come impl*/}
  };
  </code></pre>
  
  <p>Using following code,</p>
  
  <pre><code>BaseClass * bp = new DerivedClass();
  bp-&gt;foo();
  </code></pre>
  
  <p>Should be equivalent to something like,</p>
  
  <pre><code>BaseClass * bp = new DerivedClass();
  log_start(typeid(*bp).name());
  bp-&gt;foo();
  log_end(typeid(*bp).name());
  </code></pre>
  
  <p>But I can't ask my library users (and even I cann't do in everywhere) to put these logging stuff whenever they use my API. Since, there are a lot of virtual functions and their usage, I can't put logging everywhere in my lib. </p>
  
  <p>Is there any easy way to achieve this? Do I need to create my own virtual table?</p>