其他分享
首页 > 其他分享> > 自考新教材-p240_2

自考新教材-p240_2

作者:互联网

源程序:

#include <iostream>
using namespace std;

class Base
{
private:
int radius, width;
public:
Base()
{
cout << "Base默认构造函数" << endl;
}
Base(int r, int w) :radius(r), width(w)
{
cout << "Base带2个参数的构造函数" << endl;
}
~Base()
{
cout << "Base析构函数" << endl;
}
};

class D_Base
{
private:
int price;
Base ty;
public:
D_Base()
{
cout << "D_Base默认构造函数" << endl;
}
D_Base(int p, int tr, int w) :price(p), ty(tr, w)
{
cout << "D_Base带3个参数的构造函数" << endl;
}
~D_Base()
{
cout << "D_Base析构函数" << endl;
}
};

int main()
{
D_Base();
D_Base db(1,2,3);
system("pause");
return 1;
}

运行结果:

 

标签:p240,cout,ty,新教材,private,int,Base,radius,自考
来源: https://www.cnblogs.com/duanqibo/p/12260810.html