class abstractDrinking
{
public:
//煮水
virtual void boil()=0;
//冲泡
virtual void brew()=0;
//加入辅料
virtual void put()=0;
//制作饮品
void make()
{
boil();
brew();
put();
}
};
//制作咖啡
class coffee:public abstractDrinking
{
public:
virtual void boil()
{
cout<<"煮山泉"<<endl;
}
virtual void brew()
{
cout<<"冲泡咖啡"<<endl;
}
virtual void put()
{
cout<<"糖和牛奶"<<endl;
}
};
//制作茶
class tea:public abstractDrinking
{
public:
virtual void boil()
{
cout<<"煮山泉"<<endl;
}
virtual void brew()
{
cout<<"冲泡茶叶"<<endl;
}
virtual void put()
{
cout<<"加柠檬"<<endl;
}
} ;
void dowork(abstractDrinking * abs)
{
abs->make();
delete abs;//释放
}
void test01()
{
//制作咖啡
dowork(new coffee);
cout<<"----------"<<endl;
//制作茶叶
dowork(new tea);
}
int main()
{
test01();
return 0;
}
为什么在tets01中传入dowork要用new来传入啊