Why is the compiler allowing this virtual function in a template class?
<p>I know there are few threads about this topic. But what really confused me is the result I got is different from what everyone is saying.</p>

<p>Look this code below (compiled using GCC441):</p>

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

using namespace std;

template&lt;class T&gt;
class A {
  public:
    A(T &amp;t) : _a(t) {};
    virtual ~A() { cout &lt;&lt; "Dtor-A" &lt;&lt; endl;};
    virtual void print () { cout &lt;&lt; "A: " &lt;&lt; _a &lt;&lt; endl; }
    T _a;
};

class B : public A&lt;int&gt; {
  public:
    B(int t) : A&lt;int&gt;(t) {}
    ~B() { cout &lt;&lt; "Dtor-B" &lt;&lt; endl;};
    void print() { cout &lt;&lt; "B: " &lt;&lt; endl; }
};

int main() {
  B b(2);

  A&lt;int&gt; *a = &amp;b;
  a-&gt;print();

  A&lt;int&gt; *a2 = new B(4);
  a2-&gt;print();

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

<p>The result is:</p>

<pre><code>B: 
B: 
Dtor-B
Dtor-A
Dtor-B
Dtor-A
</code></pre>

<p>If virtual function is not allowed in template class, why did I get this result? </p>
