# include<iostream>
# include<string>
using namespace std;
//抽象的CPU
class CPU
{
public:
virtual void caculate() = 0;
};
//抽象的显卡
class GraphicsCard
{
public:
virtual void show() = 0;
};
//抽象的内存条
class RAM
{
public:
virtual void storage() = 0;
};
//电脑类
class Compute
{
public:
Compute(CPU* cpu, GraphicsCard* gc, RAM* ram)
{
m_cpu = cpu;
m_gc = gc;
m_ram = ram;
}
void work()
{
m_cpu->caculate();
m_gc->show();
m_ram->storage();
}
~Compute()
{
if (m_cpu != NULL)
{
delete m_cpu;
m_cpu = NULL;
}
if (m_gc != NULL)
{
delete m_gc;
m_gc = NULL;
}
if (m_ram != NULL)
{
delete m_ram;
m_ram = NULL;
|