/*一个多重继承的例子,以电脑为例,电脑由硬盘,内存,cpu构成,以下的所有函数均直接写在类中*/
#include <iostream>
#include <string>
using namespace std;
/*定义Hdd类表示硬盘*/
class Hdd
{
private:
int rpm;//转速
int size;//容量
int cache;//缓存
public:
Hdd(int r, int s, int c)
{
rpm = r;
size = s;
cache = c;
}
~Hdd(){}
void show_Hdd()
{
cout << "\nHdd" << endl;
cout << "rpm = " << rpm << "rpm" << endl;
cout << "size = " << size << "G" << endl;
cout << "cache = " << cache << "MB" << endl;
}
};
/*定义处理器类*/
class CPU
{
private:
float C_frequency;//主频
int L1;//一级缓存
int L2;//二级缓存
int L3;//三级缓存
public:
CPU(float f, int l1, int l2, int l3)
{
C_frequency = f;
L1 = l1;
L2 = l2;
L3 = l3;
}
~CPU(){}
void show_CPU()
{
cout << "\nCPU" <<
一个c++多重继承的例子
最新推荐文章于 2024-04-10 17:42:44 发布