この免責事項を作成させてください。コンストラクタまたはデストラクタでの仮想関数呼び出しについて明確に理解しています。
以下のコードでは、実験的な目的でのみ仮想デストラクタを回避しようとしています。
今私の質問は:
主に Destroy fun の呼び出しは、適切な仮想関数を呼び出します。Destroy Function への呼び出しは、適切な仮想楽しみを呼び出す必要があると期待しています。
ただし、Base デストラクタ呼び出しに配置された同じ Destroy 関数は、Base 仮想関数です。
これは静的バインディングまたはコンパイラの最適化に関連していますか?
class Base
{
public:
Base()
{
}
void Destroy()
{
callVirtual();
}
virtual void callVirtual()
{
cout<<"In Base callVirtual "<<endl;
}
~ Base()
{
cout<<"In Base Destructor"<<endl;
Destroy();
}
};
.
class Derived : public Base
{
public:
Derived()
{
}
void callVirtual()
{
cout"<<In Derived callVirtual"<<endl;
}
};
.
int main()
{
Base *pointer = new Derived();
pointer->Destroy(); // Calls the right callVirtual
return 0;
}