C++多态实现电脑组装

#include<iostream>
using namespace std;

class CPU {
public:
virtual void nCPU() = 0;
};
class VideoCard {
public:
virtual void nVideoCard() = 0;
};
class Memorry {
public:
virtual void nMemory() = 0;
};
class computer{
private :
CPU* cpu;
public:
computer(CPU * cpu) {
this->cpu = cpu;
}
void work() {
cpu->nCPU();
}
~computer() {
if (cpu != NULL) {
delete cpu;
cpu = NULL;
}
}
};

class InerNetCpu :public CPU {
void nCPU() {
cout<<"inter的CPU"<<endl;
}
};

void test() {
CPU* intercpu = new InerNetCpu;

computer* c1 = new computer(intercpu);
c1->work();

}


int main() {
test();

system("pause");
return 0;

}

昨夜西风凋碧树,独上高楼,望尽天涯路 衣带渐宽终不悔,为伊消得人憔悴 众里寻他千百度。蓦然回首,那人却在,灯火阑珊处
原文地址:https://www.cnblogs.com/X404/p/14351732.html