title: When is a vtable created in C++?
body: <p>When exactly does the compiler create a virtual function table?  </p>
  
  <p>1) when the class contains at least one virtual function.</p>
  
  <p>OR</p>
  
  <p>2) when the immediate base class contains at least one virtual function.</p>
  
  <p>OR</p>
  
  <p>3) when any parent class at any level of the hierarchy contains at least one virtual function.</p>
  
  <p>A related question to this:
  Is it possible to give up dynamic dispatch in a C++ hierarchy?</p>
  
  <p>e.g. consider the following example.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class A {
  public:
    virtual void f();
  };
  class B: public A {
  public:
    void f();
  };
  class C: public B {
  public:
    void f();
  };
  </code></pre>
  
  <p>Which classes will contain a V-Table?</p>
  
  <p>Since B does not declare f() as virtual, does class C get dynamic polymorphism?</p>