自考新教材-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_2

 

上一篇:【Leetcode 深度优先搜索】统计封闭岛屿的数目(1254)


下一篇:实数加法