#include <iostream>
using namespace std;
class Test
{
protected:
int height;
int width;
public:
void setvalue(int a,int b)
{
height=b;
width=a;
}
};
class Rectangle:public Test
{
public:
int area()
{
return(width*height);
}
};
class Triangle:public Test
{
public:
int area()
{
return(width*height/2);
}
};
void main()
{
Rectangle rect;
Triangle tri;
rect.setvalue(3,4);
tri.setvalue(3,4);
cout<<rect.area()<<endl;
cout<<tri.area()<<endl;
getchar();
}
C++类的继承
最新推荐文章于 2022-04-20 11:32:21 发布