类继承的最简单例子
#include <iostream>using namespace std;class A{public:int x1;int y1;A(int x,int y){x1 = x;y1 = y;}int getx(){return x1+y1;}};class B :public A{public:B(int x, int y ,int z):A (x,y){cout <<
·
#include <iostream>
using namespace std;
class A{
public:
int x1;
int y1;
A(int x,int y)
{x1 = x;
y1 = y;
}
int getx()
{
return x1+y1;
}
};
class B :public A
{public:
B(int x, int y ,int z):A (x,y)
{
cout << x1<<endl;
}
};
int main()
{
B b1(1, 2, 3);
cout<<b1.getx();
system("pause");
}
更多推荐
已为社区贡献3条内容
所有评论(0)