- 7
- 0
- 约1.44千字
- 约 3页
- 2017-07-09 发布于河南
- 举报
Inheritation类的继承
#include iostream
using namespace std;
class A
{
private:
int x;
public:
void setX(int b);
void DisplayX(void);
A(int a)
{
x = a;
cout constructor of A is called\n endl;
}
~A()
{
cout destructor of A is called\n endl;
}
protected:
int getX(void);
};
class B:public A
{
private:
int y;
public:
B(int a, int b):A(a)
{
y = b;
cout constructor of B is called\n endl;
}
~B()
{
cout destructor of B is called\n endl;
}
void setY(int c);
int getY(void);
void DisplayXY(void);
};
class C:private A
{
private:
int z;
public:
C(int a, int b):A(a)
{
z = b;
cout constructor of C is called\n endl;
}
~C()
{
cout destructor of C is called\n endl;
}
public:
void setZ(int c);
void setXB(int d);
int getZ(void);
void DisplayXZ(void);
};
int A::getX(void)
{
return x;
}
void A::setX(int b)
{
x = b;
}
void A::DisplayX(void)
{
cout x is x endl;
}
void B::setY(int c)
{
y = c;
}
int B::getY()
{
return y;
}
void B::DisplayXY(void)
{
cout x is getX() \t y is y endl;
}
void C::setZ(int c)
{
z = c;
}
int C::getZ(void)
{
return z;
}
void C::setXB(int d)
{
setX(d);
}
void C::DisplayXZ(void)
{
cout x is getX() \t z is z endl;
}
int main(void)
{
B b(1, 2);
b.DisplayXY();
b.setX(3);
b.setY(4);
b.DisplayXY();
C c(5, 6);
c.DisplayXZ();
c.setXB(7);
c.setZ(8);
c.DisplayXZ();
}
您可能关注的文档
- 关于PVC参数的配置说明.doc
- 基站设备功率参数取值范围.docx
- 实验06 控制结构综合程序设计.docx
- TD-LTE无线常用优化参数手册(华为)v1.0.doc
- tcsetattr函数.docx
- 已知函数定义域范围,反算参数范围习题.docx
- 向小康生活迈进的期待 练习.ppt
- 高中新课程数学(新课标人教A版)选修4-4《圆的参数方程及应用》教案.doc
- GameSalad数学函数速查表.docx
- 2014届高考语文二轮复习课件 (教师):3.1正确使用词语(包括熟语).ppt
- 2025年北京市门头沟区中考一模英语试题.docx
- 2025年北京市门头沟区中考二模英语试题.docx
- 2025年北京市丰台区中考二模英语试题.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 解析卷.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 原卷.docx
- 2025年肩颈按摩仪行业社媒趋势数据分析.docx
- 2025年人身险行业信用回顾与2026年展望.docx
- 合同法买卖合同培训课件.ppt
- 2025年全球食物系统与SDG研究报告-食物供给、食者健康、生态平衡的整体治理.docx
- 2025下半年四川乐山市川投峨眉铁合金(集团)有限责任公司对考前自测高频考点模拟试题最新.docx
原创力文档

文档评论(0)