#if 1
#include <iostream>
using namespace std;
class MakeCar
{
public:
virtual ~MakeCar(){}
virtual void makeHead() = 0;
virtual void makeTail() = 0;
virtual void makeBody() = 0;
void make()
{
makeBody();
makeHead();
makeTail();
}
};
class WBM :public MakeCar
{
public:
void makeHead()
{
cout << "制作WBM车头" << endl;
}
void makeTail()
{
cout << "制作WBM车尾" << endl;
}
void makeBody()
{
cout << "制作WBM车身" << endl;
}
};
class Bus : public MakeCar
{
public:
void makeHead()
{
cout << "制作Bus车头" << endl;
}
void makeTail()
{
cout << "制作Bus车尾" << endl;
}
void makeBody()
{
cout << "制作Bus车身" << endl;
}
};
int main()
{
MakeCar* pF = nullptr;
pF = new WBM;
pF->make();
delete pF;
pF = new Bus;
pF->make();
delete pF;
return 0;
}
#endif
#include<iostream>
#include <vector>
#include <string>
using namespace std;
class AbstractClass
{
public:
virtual ~AbstractClass(){}
void Show()
{
cout << "我是" << GetName() << endl;
}
protected:
virtual string GetName() = 0;
};
class Naruto : public AbstractClass
{
protected:
virtual string GetName()
{
return "火影史上最帅的六代目---一鸣惊人naruto";
}
};
class OnePice : public AbstractClass
{
protected:
virtual string GetName()
{
return "我是无恶不做的大海贼---路飞";
}
};
class Ye:public AbstractClass
{
public:
virtual string GetName()
{
return "我是美丽的小叶子";
}
};
int main()
{
Naruto* man = new Naruto();
man->Show();
delete man;
OnePice* man2 = new OnePice();
man2->Show();
delete man2;
Ye* ye = new Ye();
ye->Show();
delete ye;
return 0;
}