运行结果:
Constructing a student without parameter...
Constructing a student without parameter...
Tom 21
Jon 22
现在程序能够正常运行了。可见,用s1设置本科生信息和用s2p指针设置学生信息都是可行的。
覆盖(Overlap)
假设我们为学生类和本科生类都写了一个名为study的成员函数。两者的名称相同,参数表相同,实现却不相同。当子类和父类有着两个名字和参数表完全相同的函数时,我们把这个现象称为覆盖(Overlap)。如下面的代码://student.h
class student//学生类作为父类
{
public:
……
void study();
protected:










