C++ 多态案列-电脑组装
Posted 行码阁119
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ 多态案列-电脑组装相关的知识,希望对你有一定的参考价值。
# 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;
以上是关于C++ 多态案列-电脑组装的主要内容,如果未能解决你的问题,请参考以下文章