标签:highlight main new 构造器 style pac let 析构函数 std
#include <iostream> using namespace std; class A{ public: A() { cout<<"construct A"<<endl; } A(int a) { cout<<"construct int A"<<endl; } virtual ~A() //析构函数 必须 声明为 虚函数,才能彻底释放内存空间 { cout<<"destory A"<<endl; } }; class B : public A{ public: B() { cout<<"construct B"<<endl; } B(int a):A(a) //构造器调用A中int构造方法 { cout<<"construct int B"<<endl; } ~B() { cout<<"destory B"<<endl; } }; class C:public B{ public: C() { cout<<"construct C"<<endl; } ~C() { cout<<"destory C"<<endl; } }; int main() { A *p = new C(); delete p; return 0; }
标签:highlight main new 构造器 style pac let 析构函数 std
原文地址:http://www.cnblogs.com/hertzz/p/7698784.html