destructor c++ make leak memory : <p>I'm having a hard time figuring out how this destructor call</p>

<p>So I have class A with virtual destructor and inline virtual clone function</p>

<pre><code>class A{
public:
    A(){ }
    virtual ~A(){
        qDebug() &lt;&lt; "Class A destructor";
    }

    inline virtual A *clone(){
        return NULL;
    }
};
</code></pre>

<p>Then I have sub-class B also have destructor and clone function return pointer to class A</p>

<pre><code>class B : public A{
public:
    B() { }
    ~B(){
        qDebug() &lt;&lt; "Class B destructor";
    }
    A *clone(){
        B *temp = new B();
        return static_cast&lt;A *&gt;(temp);
    }
};
</code></pre>

<p>And I have main function and test function and i start do some crazy thing about pointer</p>

<pre><code>A *test(A *input){
    return input-&gt;clone();
}

int main(){

    B temp2;
    A *temp = test(&amp;temp2);
    delete temp;

    return 0;
}
</code></pre>

<p>Finally if I have the output is </p>

<pre><code>Class B destructor
Class A destructor
Class B destructor
Class A destructor
</code></pre>

<p>and if I'm not using virtual before destructor class A, I have ouput is</p>

<pre><code>Class A destructor
Class B destructor
Class A destructor
</code></pre>

<p>So can anyone explain me why virtual make so much different</p>
