#include#includeusing namespace std;class Vehicle{public:\x05virtual void showinfo()=0;protected:\x05char Name[20];};class Car:public Vehicle{public:\x05Car(char *name)\x05{\x05\x05strcpy(Name,name);\x05}\x05void showinfo(){cout
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 21:33:47
#include#includeusing namespace std;class Vehicle{public:\x05virtual void showinfo()=0;protected:\x05char Name[20];};class Car:public Vehicle{public:\x05Car(char *name)\x05{\x05\x05strcpy(Name,name);\x05}\x05void showinfo(){cout
#include
#include
using namespace std;
class Vehicle{
public:
\x05virtual void showinfo()=0;
protected:
\x05char Name[20];
};
class Car:public Vehicle{
public:
\x05Car(char *name)
\x05{
\x05\x05strcpy(Name,name);
\x05}
\x05void showinfo(){cout
#include#includeusing namespace std;class Vehicle{public:\x05virtual void showinfo()=0;protected:\x05char Name[20];};class Car:public Vehicle{public:\x05Car(char *name)\x05{\x05\x05strcpy(Name,name);\x05}\x05void showinfo(){cout
vp = &car; //将vp指向car
vp -> showinfo(); //通过vp调用成员函数showinfo(),相当于car.showinfo()
vp = &truck; //将vp指向truck
vp -> showinfo(); //通过vp调用成员函数showinfo(),相当于truck.showinfo()
vp = &boat; //将vp指向boat
vp -> showinfo(); //通过vp调用成员函数showinfo(),相当于boat.showinfo()