#include#includeusing namespace std;class Vehicle{public:\x0
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/19 03:11:37
#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
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
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()
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()