#include<iostream> using namespace std; class Base { int x; public: Base(int a) { x = a; cout<<"father constructing "<<x<<endl; } ~Base() { cout<<"father destructing "<<x<<endl; } }; class Dervied:public Base { int y; Base B2,B1;//只与定义顺序有关 public: Dervied(int a = 0,int b = 0,int c = 0,int d = 0):B1(d),Base(b),B2(c),y(a)//与参数列表的顺序无关 { cout<<"son constructing "<<y<<endl; } ~Dervied() { cout<<"son destructing "<<y<<endl; } }; int main() { Dervied(1,2,3,4); return 0; }
原文地址:http://blog.csdn.net/cherry_ermao/article/details/44963039