洛阳理工学院实验报告
系别
计算机与信
班级
B11050
学号
B11050
姓名
息工程系
课程名称
C++面向对象与程序设计
实验日期
实验名称
派生类与继承
I成绩
实验目的:>ocu™e(its and FMti呗帥ni血Hator、桌耐rtiij■唧⑴];see deddNlinn dF 'f
Errar wecuting .
r训』bj -1 error[s), 0 祈fni叫(5)
因为基类Base中数据成员x的访问权限改为protected时,公用基类的保护成员 在公用派生类中的访问属性仍然是保护,在公用派生类外就不能通过公用派生类的对 象访问该成员,所以出现了错误。
③在源程序的基础上,将派生类 Derived的继承方式改为private时,会出现哪
些错误?为什么?
切甲ili凹
C:\Dacunfit£ and SeCting^(2AJ : error 血岖:'set*' : cannot men public nenher dttlarrd in □砧s "臨e' C:\Dociinents and ttlngs\Adnnistrator-0(1()CS] : see d^cl^ratiait 肝'ietx'
C:\Cocunents and 昶tting斟MnniEt恂toiA臬血rtu卜叩p寿):errar C22iiS: 'x' : cannot accES? publiE hiMw dtclar^d in class 'Bast' C:\Dvcunfnts ini SettingsVfldiiiiiistraterV^.eppC1B) ; its dfcljratiun cf 'n'
匸:训ocunp血 ini Settingi^ndnnistrjtar\^.epp(31) : frror C221i8: 'gptit' : cannot access public npnher d^clar^d in cl^ss '臨丁 C:\[iacuinBnt£ and ⑴:Sfe dfCl^Ntion oF 'gelK'
Error exFciiting
rluy*cbj - 3 trror估h 8 uarringf^)
将派生类Derived的继承方式改为private时,私有基类中的公用成员在私有派 生类中的访问属性为私有,在类外不能通过对象调用私有成员,只能通过成员函数调 用.
④在源程序的基础上,将派生类 Derived的继承方式改为protected时,会出现
哪些错误?为什么?
ConfiguratiDll: t - Win眈 Debug
佃叩 iling+r
c;\[]ocuiipiits and setting5\adninistrator\Lcpp[26) : error C22i(8: 'sptx' : cannot access public iKidpr declared in cUss 'Base' c:\docuw[its and settings\iJuinistratar\t,cpp(E) ; see declaration of 'seh'
c:\docuiipiits and settings\adninistrator\Lcpp[29) : error 促测:* : cdirnot access public nember declared in class ' Base * c:ld(Miwnts and settings\ jdninisttQr\(1 fl) : 5ee tiHlmration 肝 霍‘
因为私有继承时基类中的公有函数到派生类中一是私有成员, 不能通过对象访问,
只能通过成员函数来访问。
编写一个学生和教师的数据输入和显示程序。学生数据有编号、姓名、性别、 年龄、系别和成绩,教师数据有编号、姓名、性别、年龄、职称和部门。要求将编号、 姓名、性别、年龄的输入和显示设计成一个类 Person,并作为学生类Student和教师
类Teacher的基类。
供参考的类结构如下:
class Person{
};
class Stude nt:p ublic Person{
};
class Teacher: public Person{ };
程序代码:
#in clude<iostream>
#in cludevstri ng>
using n ames pace std;
cla
派生类与继承实验报告 来自淘豆网m.daumloan.com转载请标明出处.