#include <iostream>
using namespace std;
class Circle {
double radius;
public:
Circle (double r) : radius (r) {}
double area () {return radius*radius*3.1415926;}
};
class Cylinder {
Circle base;
double height;
public:
Cylinder (double r, double h) : base (r), height (h) {}
double volume () {return base.area() * height;}
};
int main(int argc, char const *argv[])
{
Cylinder foo (10, 2);
cout << "foo's volume: " << foo.volume() << endl;
return 0;
}
c++构造器中成员函数初始化
最新推荐文章于 2024-09-10 16:06:07 发布