还有全局函数
#include<iostream> using namespace std; class A{ public : virtual ~A() =0{ cout<<"destroy A"<<endl; } virtual void dump() const =0; }; class B:public A{ public: ~B() { cout<<"destroy B"<<endl; } void dump() const{ cout<<"B"<<endl; } }; class C:public A{ public : ~C() { cout<<"destroy C"<<endl; } void dump() const{ cout<<"C"<<endl; } }; void Print(const A* pa) { pa->dump(); } int main(void) { A* pa = new B; Print(pa); delete pa; return; }