一般物件在生命週期結束時,會呼叫解構函式,以便執行釋放資源的動作。但對於實作介面的物件,如果是以介面指標的方式來呼叫,竟然不會呼叫解構函式,Oh My God。讓我們一步一步來看看吧! #include "stdafx.h" #include <iostream> using namespace std; struct IAnimal { virtual void Eat() = 0; }; class Dog : public IAnimal { public: Dog() { cout << "Dog construct." << endl; } ~Dog() { cout << "Dog destruct." << endl; } void Eat() { cout << "Dog eat ..." << endl; } }; int _tmain(int argc, _TCHAR* argv[]) { Dog* pDog = new Dog(); pDog->Eat(); delete pDog; return 0; }