#include#include using namespace std; class abstractdrinking { public: //煮水 virtual void boil() = 0; //冲茶 virtual void brew() = 0; //加入杯中 virtual void pourincup() = 0; //加入辅料 virtual void putsomething() = 0; void makedrink() { boil(); brew(); pourincup(); putsomething(); } }; //煮咖啡 class coffee :public abstractdrinking { //煮水 virtual void boil() { cout << "放入农夫山泉" << endl; } //冲茶 virtual void brew() { cout << "冲泡咖啡" << endl; } //加入杯中 virtual void pourincup() { cout << "倒入杯中" << endl; } //加入辅料 virtual void putsomething() { cout << "加入糖和牛奶" << endl; } }; //煮茶叶 class tea :public abstractdrinking { //煮水 virtual void boil() { cout << "放入农夫山泉" << endl; } //冲茶 virtual void brew() { cout << "冲泡茶叶" << endl; } //加入杯中 virtual void pourincup() { cout << "倒入杯中" << endl; } //加入辅料 virtual void putsomething() { cout << "加入枸杞" << endl; } }; void zhizuo(abstractdrinking*a) { a->makedrink(); delete a;//释放 } void test1() { zhizuo(new coffee); cout << "-------------" << endl; zhizuo(new tea); } int main() { test1(); system("pause"); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)