虚基类释义

news/2024/7/7 11:31:36

#include "stdafx.h"

#include
#include

using namespace std;

class person{//声明基类
protected:
 int age;
 char sex;
 string name;
public:
 person(int a,char s,string nam){
  age=a;
  sex=s;
  name=nam;
 }
};
class teacher:virtual public person
{
protected:
 string title;
public:
 teacher(int a,char s,string nam,string t):person(a,s,nam){
  title=t;
 }
};
class student:virtual public person
{
protected:
 float score;
public:
 student(int a,char s,string nam,float sc):person(a,s,nam){
  score=sc;
 }
};
class graduate:public teacher,public student
{
protected:
 float wdge;
public:
 graduate(int a,char s,string nam,string t,float sc,float wd):person(a,s,nam),teacher(a,s,nam,t),student(a,s,nam,sc){
  wdge=wd;
 }
 void show(){
  cout< <
  cout< <
  cout< <
  cout< <
  cout< <
  cout< <
 }
};
int main(){
 graduate gr(22,'f',"k;asdjf;daf","klsdaf",89.5,79.5);
 gr.show();
 return 0;
}

输出结果:

k;asdjf;daf
22
f
klsdaf
89.5
79.5
Press any key to continue 



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1476036



http://www.niftyadmin.cn/n/3658780.html

相关文章

在Linux下后台运行,程序运行前后台切换

一、为什么要使程序在后台执行 我们计算的程序都是周期很长的&#xff0c;通常要几个小时甚至一个星期。我们用的环境是用Xshell远程连接到Linux服务器。所以使程序在后台跑有以下两个好处&#xff1a; 1&#xff1a;我们这边是否关机不影响服务器的程序运行。&#xff08;不…

C++多继承的细节

这几天写的程序应用到多继承。以前对多继承的概念非常清晰&#xff0c;可是很久没用就有点模糊了。重新研究一下&#xff0c;“刷新”下记忆。 假设我们有下面的代码&#xff1a; #include class A { private: char data; public: A(){data A;} virtual void Show(){printf(&q…

Qt读写文件的简单封装

C#中&#xff0c;有下列函数可以简单地读写文件&#xff1a;读: temp File.ReadAllText("abc.txt",Encoding.Default); 写: File.WriteAllText("abc.txt", temp, Encoding.Default);追加: File.AppendAllText("abc.txt", temp, Encoding.Def…

web http方法

Post&#xff08;新增&#xff09;,Put&#xff08;修改&#xff09;,Delete&#xff08;删除&#xff09;,Get&#xff08;查询&#xff09; GET&#xff1a;生到数据列表&#xff08;默认&#xff09;&#xff0c;或者得到一条实体数据 POST&#xff1a;添加服务端添加一条…

将项目托管到gitHub

一、下载并安装Git版本控制工具 下载地址&#xff1a;https://git-scm.com/downloads 注册GitHub账号&#xff1a;https://github.com/ 为什么托管到GitHub要下载Git&#xff1f; git是一个版本控制工具   github是一个用git做版本控制的项目托管平台。 二、在IEDA中设置G…

C++中对文件进行读写操作

#include "stdafx.h"#include#include#includeusing namespace std;//从键盘上读取字符的函数void read_save(){ char c[80]; ofstream outfile("f1.dat"); //以输出方工打开文件 if(!outfile){ cerr<<"open error!"<exit(1); }…

降级论:智商高的IT人,你比沙县老板强吗

从前有三个屌丝&#xff0c;聚在一起做网络&#xff0c;提供免费的网络服务&#xff0c;砸锅卖铁&#xff0c;通宵达旦&#xff0c;除了卖肾啥都做了。3年后终于做到了五百万用户&#xff0c;对于年轻人来说&#xff0c;能把五百万人玩弄于鼓掌之间&#xff0c;已经是很牛逼轰轰…

用指向基类对象的指针输出数据

#include "stdafx.h"#include#includeusing namespace std;class student{private: int num; int age; float score;public: student(int ,int ,float); void display();};//定义构造函数 student::student(int n,int a,float sc):num(n),age(a),score(sc){}void stu…