多继承
来源:互联网 发布:淘宝客内部优惠券app 编辑:程序博客网 时间:2024/05/06 08:52
#include<iostream>
using namespace std;
#include<stdlib.h>
class Father
{
public :
void setA(int a){tall=a;};
void print1(){cout<<"身高:"<<tall<<endl;};
private:
int tall;
};
class mother
{
public: //不写public 默认是private
void setB(int a ){weight=a;};
void print2(){cout<<"体重:"<<weight<<endl;};
private:
int weight;
};
class son:public Father,public mother //不写public ,默认是private,如果是private 则mother类的公有成员在son 类中是private属性,私有成员在son类中不可访问
{
public:
void setD(int a ){ age=a;};
void print3(){ print1();print2();cout<<"年龄:"<<age<<endl;};
private:
int age;
};
int main()
{
son mick;
mick.setA(174);
mick.setB(80);
mick.setD(32);
mick.print3();
getchar();
return 0;
}
using namespace std;
#include<stdlib.h>
class Father
{
public :
void setA(int a){tall=a;};
void print1(){cout<<"身高:"<<tall<<endl;};
private:
int tall;
};
class mother
{
public: //不写public 默认是private
void setB(int a ){weight=a;};
void print2(){cout<<"体重:"<<weight<<endl;};
private:
int weight;
};
class son:public Father,public mother //不写public ,默认是private,如果是private 则mother类的公有成员在son 类中是private属性,私有成员在son类中不可访问
{
public:
void setD(int a ){ age=a;};
void print3(){ print1();print2();cout<<"年龄:"<<age<<endl;};
private:
int age;
};
int main()
{
son mick;
mick.setA(174);
mick.setB(80);
mick.setD(32);
mick.print3();
getchar();
return 0;
}
- 多继承 虚继承
- 多继承 菱形继承
- 继承 和 多继承
- 继承(单继承、多继承、菱形继承、虚继承)
- 继承、父子类、单继承、多继承
- 继承、多继承、菱形虚拟继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- 多继承
- copy,mutableCopy 理解
- 整数划分(2)
- nyoj-852-蛇形填数(二)
- “你最喜欢的程序员漫画”精选
- erlang shell 命令中文使用说明
- 多继承
- 使用 CXF 做 webservice 简单例子
- svn查看指定release的revision号
- restlet中如何返回json和xml类型数据
- sql DATENAME 用法
- Brief Intro to Archives and Serialization of Foundation Framework
- codeforces 359A
- 大数据加法(string与int转化)
- 第13周项目7-递归法求Fibnacci序列的第20个数