马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using std::cout,std::endl;
//CPU类
class CPU
{
public:
virtual void calculate() = 0;
};
//显卡类
class VideoCard
{
public:
virtual void display() = 0;
};
//内存条类
class Memory
{
public:
virtual void storage() = 0;
};
//电脑类
class Computer {
public:
Computer(CPU * cpu,VideoCard * vc,Memory * mem)
{
m_cpu = cpu;
m_vc = vc;
m_mem = mem;
}
void work()
{
m_cpu->calculate();
m_vc->display();
m_mem->storage();
}
private:
CPU* m_cpu; //CPU零件指针
VideoCard* m_vc; //显卡内存指针
Memory* m_mem; //内存条零件指针
};
//具体厂商
//InteL厂商
class IntelCPU :public CPU
{
public:
virtual void calculate()
{
cout << "Intel厂商的CPU开始计算了!" << endl;
}
};
class IntelVideoCard :public VideoCard
{
public:
virtual void display()
{
cout << "Intel厂商的显卡开始显示了!" << endl;
}
};
class IntelMemory :public Memory
{
public:
virtual void distorage()
{
cout << "Intel厂商的内存条开始存储了了!" << endl;
}
};
//Lenovo厂商
class LenovoCPU :public CPU
{
public:
virtual void calculate()
{
cout << "Lenovo厂商的CPU开始计算了!" << endl;
}
};
class LenovoVideoCard :public VideoCard
{
public:
virtual void display()
{
cout << "Lenovo厂商的显卡开始显示了!" << endl;
}
};
class LenovoMemory :public Memory
{
public:
virtual void distorage()
{
cout << "Lenovo厂商的内存条开始存储了了!" << endl;
}
};
void test01()
{
//第一台电脑的零件
CPU* intelCpu = new IntelCPU;
VideoCard* intelCard = new IntelVideoCard;
Memory* intelMem = new IntelMemory; //无法实例化这个抽象函数
//创建第一台电脑
Computer* computer1 = new Computer(intelCpu,intelCard,intelMem);
computer1->work();
delete computer1;
};
int main() {
test01();
system("pause");
return 0;
}
名字写错了,你上面写的类 class Memory 里面是 storage() 怎么到了下面变成 distorage() 了?
|