子类调用父类构造函数和析构函数的顺序

2014-11-10 20:00:09 · 作者: · 浏览: 39

  #include


  class B


  {


  public:


  B(); //与类同名,构造函数


  B(int i);


  ~B(); //~析构函数


  void Print() const;//const,常量成员,不能修改


  private:


  int b;


  };


  B:B()


  {


  b=0;


  cout < < "B 's default constructor called. " <


  }


  B::B(int i)


  {


  b=i;


  cout < < "B 's constructor called. " <


  }


  B::~B()


  {


  cout < < "B 's destructor called. " <


  }


  void B:Print() const


  {


  cout <


  }