C++类中的继承
来源:互联网 发布:逆战刷永久枪软件 编辑:程序博客网 时间:2024/06/06 01:49
#include<iostream>#include<string>using namespace std;class Person{public:Person(const char* name = "abc"):_name(name){cout << "Person()" << endl;}Person(const Person& pp):_name(pp._name){cout << "Person(const Person&)" << endl;}Person& operator=(const Person& pp){cout << "Person& operator=(const Person&)" << endl;if (this != &pp){_name = pp._name;}return *this;}~Person(){cout << "~Person()" << endl;}protected:string _name;};class Student :public Person{public:Student(const char* name, int num):Person(name), _num(num){cout << "Student()" << endl;}Student(const Student& A):Person(A), _num(A._num){cout << "Student(const Student& A)" << endl;}Student& operator=(const Student& A){cout << "Student& operator=(const Student& A)" << endl;if (this != &A){Person::operator=(A);_num = A._num;}return *this;}~Student(){cout << "~Student()" << endl;}private:int _num;};void test(){Student a1("peter", 20);Student a2(a1);a2 = a1;}int main(){test();return 0;}
0 0
- C++--继承中的类模板语法
- 【C++】c++中的继承
- 浅谈Objective-C中的继承
- 【C++】浅谈C++中的继承
- 【C++】浅析C++中的继承
- C语言中的类模拟和多态,继承
- C语言中的类模拟和多态,继承
- 【C#】C#中的继承 (继承、抽象类和抽象方法、接口)
- JavaScript中的类继承
- JavaScript中的类继承
- JavaScript中的类继承
- JavaScript中的类继承
- JavaScript中的类继承
- EXTJS中的类继承
- JavaScript中的类继承
- jaxb中的类继承
- C++类中的继承
- C++类中的继承
- Get与Post的区别
- Winccde TreeView控件初步使用
- delay.c
- CONFIG_OF 宏解释
- C#解决WebBrowser DocumentComplete一个网页多次触发
- C++类中的继承
- [转载]SSH 登录失败:Host key verification failed 的处理方法
- PHP 面向对象OOP
- sql server 查询某个表的所有触发器名称
- 05 单片机串口
- pom文件标签详细备注
- 小程序开发基本框架及其限制与优化
- 全国各个城市代码
- swift3.0 protocol 概览——boolan