Why is my virtual function not being called?
<p>I'm having trouble with virtual methods. When I call <code>f</code> it doesn't work. Why?</p>

<pre><code>#include &lt;iostream&gt;

struct A {
   virtual void f() const { std::cout &lt;&lt; "In A"; }
   virtual ~A() {};
};

struct B : A {
   void f() const { std::cout &lt;&lt; "In B"; }
};

int main()
{
   A* a = new A();

   B* b = dynamic_cast&lt;B*&gt;(a);

   (*b).f();


   delete a;
}
</code></pre>

<p>It doesn't print anything at all, and I don't get any errors. What did I do wrong?</p>
