#include<iostream>
using namespace std;
class A
{ private: int x;
public:  A(){ cout<<"A Constructor 1..."<<endl;}
A(int i) { x=i; cout<<"A Constructor 2..."<<endl; }
void disp_x(){  cout<<"x= "<<x<<endl; }


};


class B:public A
{
private: int y;
public: B() { cout<<"B Constructor 1..."<<endl;}
B(int j):A(j+10) //使用 基类的构造函数来初始化
{  y=j; cout<<"B Constructor 2..."<<endl;   }

void disp_y()   { disp_x(); cout<<"y= "<<y<<endl; } 
};


int main()
{
B b(2);
b.disp_y();
}



单继承的构造函数2

相关文章:

  • 2021-10-03
  • 2021-07-07
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
猜你喜欢
  • 2021-12-09
  • 2021-09-18
  • 2022-02-23
  • 2021-08-31
  • 2021-09-17
  • 2021-08-30
相关资源
相似解决方案