#include<iostream>
using namespace std;
class People
{
private :
int age;
char sex;
public:
People(int age,char sex)
{
this->age=age;
this->sex=sex;
};
People()
{
age=0;
sex='m';
}
virtual void Work()
{
cout<<"people work"<<endl;
}
int getAge()
{
return age;
}
friend std::ostream & operator<<(std::ostream &os,const People &people)
{
os<<" age "<<people.age<<" sex is "<<people.sex;
return os;
}
People operator+=(const People &pe)
{
this->age+=pe.age;
return *this;
}
People operator+=(int age)
{
this->age+=age;
return *this;
}
People operator-=(int age)
{
this->age-=age;
return *this;
}
People operator-(int age)
{
this->age-=age;
return *this;
}
People operator=(const People &pe)
{
if (*this==pe) return *this;
this->age=pe.age;
this->sex=pe.sex;
return *this;
}
int operator==(const People &pe)
{
if (this->age==pe.age && this->sex==pe.sex)
return 1;
else
return 0;
}
};
class ColleageStudent:public People
{
public:
ColleageStudent(){}
ColleageStudent(int age,char sex):People(age,sex){}
virtual void Work()
{
cout<<"collage student work"<<endl;
}
};
int main()
{
ColleageStudent c(12,'s');
c.Work();
People *t=new ColleageStudent(20,'s');
t->Work();
cout<< c.getAge();
*t+=3;
People t2;
t2=*t;
cout<<t2<<endl;
delete t;
return 0;
}
分享到:
相关推荐
C++继承与多态性实验报告
在Qt中编写的c++继承的视频
C++ 继承详解 C++ C++ 继承详解 C++ 继承详解 继承详解
C++继承与派生课件 很值得下载 C++继承与派生课件 很值得下载
08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08_31_C++ 继承的二义性08...
C++中继承与派生的PPT课件 欢迎新手们参考
在Qt中编写的c++继承分类的视频
C++实现的一个继承与多态的例子,内容详细且易懂
c++继承描述
c++继承与派生,上机操作题,帮助理解继承与派生
c++程序设计 继承与派生实验(二) 1. 进一步掌握类的派生与继承的概念、应用方法 2. 掌握继承方式对成员访问权限的影响 3. 掌握虚基类的用法
C++继承,虚函数与多态性专题.C++继承,虚函数与多态性专题.
利用C++中的继承与多态,实验构造函数的作用
信息科学技术学院《程序设计实习》,C++程序员入门级教程
c++继承与派生习题答案
入门基础实例 有关继承和派生的应用小程序 希望对大家有帮助
本资源是C++继承与派生类实验报告,欢迎大家下载阿!
c++上的一道题,网上尚未有答案,来自郭文平老师的书
C++继承与多态C++继承与多态C++继承与多态C++继承与多态C++继承与多态C++继承与多态
C++多继承Demo(资源包括源代码文档和编译好的exe文件)