例4.6 当基类含有参数的构造函数,派生类构造函数的构造方法
来源:互联网 发布:美国 私人飞机 知乎 编辑:程序博客网 时间:2024/06/05 02:40
// 例4.6 当基类含有参数的构造函数,派生类构造函数的构造方法。#include<iostream>#include<string>using namespace std;class Student{public: Student(int number1,string name1,float score1){ number = number1; name = name1; score = score1; } void print(){ cout<<"number:"<<number<<endl; cout<<"name:"<<name<<endl; cout<<"score:"<<score<<endl; } protected: int number; //学号 string name; //姓名 float score; //成绩};class UStudent:public Student{public: UStudent(int number1,string name1,float score1,string major1):Student(number1,name1,score1){//定义派生类构造函数时,缀上要调用的基类的构造函数及其参数 major = major1; } void print1(){ print(); cout<<"major:"<<major<<endl; }private: string major; //专业};int main(){UStudent stu(22116,"张国立",98,"计算机及应用");stu.print1();cout<<"-----------------------------------------"<<endl;UStudent xi(223,"习近平",22,"管理");xi.print1();return 0;}
阅读全文
0 0
- 例4.6 当基类含有参数的构造函数,派生类构造函数的构造方法
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 派生类的构造函数
- 什么是云计算?
- LiDAR-Velodyne激光雷达pcap文件解析
- 反转字符串、整形数组某个数字出现的次数、排序
- 单链表
- #POJ3262#Protecting the Flowers(贪心)
- 例4.6 当基类含有参数的构造函数,派生类构造函数的构造方法
- android自定义view(一)
- python触发异常——raise语句
- myeclipse 10 安装了JDK1.7,java编译器无法选择到1.7的问题
- 【BZOJ 1715】 [Usaco2006 Dec]Wormholes 虫洞
- 【集训】jzoj 2017.7.15 noip模拟赛A 总结
- CF 149D Coloring Brackets(区间DP,好题,给配对的括号上色,求上色方案数,限制条件多,dp四维)
- 让IjkPlayer支持插入自定义的GPU滤镜
- 3次握手中的最后一个ACK服务端收到了吗