标签:技术 int 图片 掌握 name rtu string play tca
#include <iostream> #include <string> using namespace std; class MachinePets{ public: MachinePets(const string s):nickname(s){ } virtual string talk()=0; string getNickname(){ return nickname; } private: string nickname; }; class PetCats:public MachinePets{ public: PetCats(const string s):MachinePets(s){} string talk(){ return " says miao wu~" ; } }; class PetDogs : public MachinePets{ public: PetDogs(const string s):MachinePets(s){} string talk(){ return " says wang wang~"; } }; void play(MachinePets *p){ cout<<p->getNickname()<<p->talk()<<endl; } int main(){ PetCats cat("miku"); PetDogs dog("da huang"); play(&cat); play(&dog); return 0; }
实验总结:掌握了虚构函数,希望能再多加练习
标签:技术 int 图片 掌握 name rtu string play tca
原文地址:https://www.cnblogs.com/mzx1999/p/10976477.html