#include <iostream>
using namespace std;
//基类
class Shape
{
public:
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// 派生类
class Rectangle:public Shape
{
public:
int getArea()
{
return (width*height);
}
};
int main(void)
{
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
cout << Rect.getArea() << endl;
system("pause");
return 0;
}
C++派生类
猜你喜欢
转载自blog.csdn.net/qq2942713658/article/details/81783531
今日推荐
周排行