fix vitual base classes issues: add virtual destruct functions.

master
FengJungle 2021-04-04 21:09:08 +08:00
parent 80c928a497
commit 5b21352028
29 changed files with 63 additions and 17 deletions

View File

@ -12,9 +12,10 @@ public:
AbstractSportProduct(){
}
virtual ~AbstractSportProduct(){}
//抽象方法:
void printName(){};
void play(){};
virtual void printName(){};
virtual void play(){};
};
//具体产品类Basketball
@ -24,6 +25,10 @@ public:
Basketball(){
printName();
play();
}
~Basketball()
{
}
//具体实现方法
void printName(){
@ -41,6 +46,10 @@ public:
Football(){
printName();
play();
}
~Football()
{
}
//具体实现方法
void printName(){
@ -58,6 +67,10 @@ public:
Volleyball(){
printName();
play();
}
~Volleyball()
{
}
//具体实现方法
void printName(){

View File

@ -12,9 +12,10 @@ public:
AbstractSportProduct(){
}
virtual ~AbstractSportProduct(){}
//抽象方法:
void printName(){};
void play(){};
virtual void printName(){};
virtual void play(){};
};
//具体产品类Basketball
@ -72,6 +73,7 @@ public:
class AbstractFactory
{
public:
virtual ~AbstractFactory(){}
virtual AbstractSportProduct *getSportProduct() = 0;
};

View File

@ -12,8 +12,9 @@ public:
AbstractBall(){
}
virtual ~AbstractBall(){}
//抽象方法:
void play(){};
virtual void play(){};
};
//具体产品类Basketball
@ -47,8 +48,9 @@ class AbstractShirt
{
public:
AbstractShirt(){}
virtual ~AbstractShirt(){}
//抽象方法:
void wearShirt(){};
virtual void wearShirt(){};
};
//具体产品类BasketballShirt
@ -81,6 +83,7 @@ public:
class AbstractFactory
{
public:
virtual ~AbstractFactory() {}
virtual AbstractBall *getBall() = 0;
virtual AbstractShirt *getShirt() = 0;
};

View File

@ -5,7 +5,7 @@
#include <string.h>
using namespace std;
//产品类House
//<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>House
class House
{
public:
@ -19,7 +19,7 @@ public:
void setRoof(string iRoof) {
this->roof = iRoof;
}
//打印House信息
//<EFBFBD><EFBFBD>ӡHouse<EFBFBD><EFBFBD>Ϣ
void printfHouseInfo() {
printf("Floor:%s\t\n", this->floor.c_str());
printf("Wall:%s\t\n", this->wall.c_str());
@ -31,7 +31,7 @@ private:
string roof;
};
//抽象建造者AbstractBall
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>AbstractBall
class AbstractBuilder
{
public:
@ -46,7 +46,7 @@ public:
house = nullptr;
}
}
//抽象方法:
//<EFBFBD><EFBFBD><EFBFBD>󷽷<EFBFBD><EFBFBD><EFBFBD>
virtual void buildFloor() = 0;
virtual void buildWall() = 0;
virtual void buildRoof() = 0;
@ -55,7 +55,7 @@ public:
House *house;
};
//具体建造者ConcreteBuilderA
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ConcreteBuilderA
class ConcreteBuilderA :public AbstractBuilder
{
public:
@ -70,7 +70,7 @@ public:
house = nullptr;
}
}
//具体实现方法
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
void buildFloor() {
this->house->setFloor("Floor_A");
}
@ -85,7 +85,7 @@ public:
}
};
//具体建造者ConcreteBuilderB
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ConcreteBuilderB
class ConcreteBuilderB :public AbstractBuilder
{
public:
@ -100,7 +100,7 @@ public:
house = nullptr;
}
}
//具体实现方法
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
void buildFloor() {
this->house->setFloor("Floor_B");
}
@ -115,7 +115,7 @@ public:
}
};
//指挥者Director
//ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Director
class Director
{
public:
@ -128,7 +128,7 @@ public:
builder = nullptr;
}
}
//具体实现方法
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
void setBuilder(AbstractBuilder *iBuilder) {
this->builder = iBuilder;
}

View File

@ -20,6 +20,7 @@ class PrototypeWork
{
public:
PrototypeWork(){}
virtual ~PrototypeWork(){}
virtual PrototypeWork *clone() = 0;
private:

View File

@ -11,6 +11,7 @@ class Controller
{
public:
Controller(){}
virtual ~Controller(){}
virtual void pathPlanning() = 0;
private:
};

View File

@ -11,6 +11,7 @@ class Game
{
public:
Game(){}
virtual ~Game(){}
virtual void play() = 0;
private:
};
@ -41,6 +42,7 @@ class Phone
public:
Phone(){
}
virtual ~Phone(){}
//°²×°ÓÎÏ·
virtual void setupGame(Game *igame) = 0;
virtual void play() = 0;

View File

@ -14,6 +14,7 @@ public:
Component(string iName){
this->name = iName;
}
virtual ~Component(){}
//增加一个部门或办公室
virtual void add(Component*) = 0;
//撤销一个部门或办公室

View File

@ -6,6 +6,7 @@ class Component
{
public:
Component(){}
virtual ~Component(){}
virtual void operation() = 0;
};

View File

@ -10,6 +10,7 @@ class NetDevice
{
public:
NetDevice(){}
virtual ~NetDevice(){}
virtual string getName() = 0;
/*void print(){

View File

@ -10,6 +10,7 @@ class Subject
{
public:
Subject(){}
virtual ~Subject(){}
virtual void method() = 0;
};
@ -18,6 +19,7 @@ class RealSubject :public Subject
{
public:
RealSubject(){}
virtual ~RealSubject(){}
void method(){
printf("调用业务方法\n");
}

View File

@ -36,6 +36,7 @@ public:
Approver(string iName){
setName(iName);
}
virtual ~Approver(){}
// 添加上级
void setSuperior(Approver *iSuperior){
this->superior = iSuperior;

View File

@ -13,6 +13,7 @@ class Command
{
public:
Command(){}
virtual ~Command(){}
// 声明抽象接口:发送命令
virtual void execute() = 0;
private:

View File

@ -9,6 +9,7 @@ class AbstractNode
{
public:
AbstractNode(){}
virtual ~AbstractNode(){}
// ÉùÃ÷³éÏó½Ó¿Ú
virtual char interpret() = 0;
};

View File

@ -17,5 +17,5 @@ int Television::getTotalChannelNum(){
}
void Television::play(int i){
printf("现在播放:%s……\n", channelList[i].c_str());
printf("<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>ţ<EFBFBD>%s<><73><EFBFBD><EFBFBD>\n", channelList[i].c_str());
}

View File

@ -13,6 +13,7 @@ class Aggregate
{
public:
Aggregate(){}
virtual ~Aggregate(){}
virtual Iterator* createIterator() = 0;
};

View File

@ -13,6 +13,7 @@ class Colleague
{
public:
Colleague(){}
virtual ~Colleague(){}
void setMediator(Mediator* iMediator){
this->mediator = iMediator;
}

View File

@ -9,6 +9,7 @@ class Mediator
{
public:
Mediator(){}
virtual ~Mediator(){}
// 声明抽象方法
virtual void operation(Colleague*) = 0;
// 声明注册方法

View File

@ -13,6 +13,7 @@ class AllyCenter
{
public:
AllyCenter();
virtual ~AllyCenter(){}
// 声明通知方法
virtual void notify(INFO_TYPE infoType, std::string name) = 0;
// 加入玩家

View File

@ -8,6 +8,7 @@ using namespace std;
class Observer
{
public:
virtual ~Observer() {}
// 声明响应更新方法
virtual void update() = 0;
};
@ -26,6 +27,7 @@ public:
class Subject
{
public:
virtual ~Subject() {}
// 添加观察者
void attach(Observer* obs){
obsList.push_back(obs);

View File

@ -10,6 +10,7 @@ using namespace std;
class Observer
{
public:
virtual ~Observer(){}
Observer(){}
// 声明抽象方法
virtual void call(INFO_TYPE infoType, AllyCenter* ac) = 0;

View File

@ -5,6 +5,7 @@
class State
{
public:
virtual ~State(){}
// 声明抽象方法
virtual void handle() = 0;
};

View File

@ -7,6 +7,7 @@ class Level
{
public :
Level();
virtual ~Level(){}
// 声明方法
void playCard();
void play();

View File

@ -8,6 +8,7 @@ class Strategy
{
public:
Strategy(){}
virtual ~Strategy(){}
virtual void sort(int arr[], int N) = 0;
};

View File

@ -5,6 +5,7 @@
class AbstractClass
{
public:
virtual ~AbstractClass(){}
// 模板方法,定义一个算法的框架流程
void templateMethod(){
// do something

View File

@ -8,6 +8,7 @@ class FingerprintModule
{
public:
FingerprintModule(){}
virtual ~FingerprintModule(){}
void getImage(){
printf("²ÉÖ¸ÎÆͼÏñ\n");
}

View File

@ -5,6 +5,7 @@
class Visitor
{
public:
virtual ~Visitor() {}
virtual void visit(ConcreteElementA*) = 0;
virtual void visit(ConcreteElementB*) = 0;
};
@ -26,6 +27,7 @@ public:
class Element
{
public:
virtual ~Element() {}
// 声明抽象方法,以一个抽象访问者的指针作为函数参数
virtual void accept(Visitor*) = 0;
};

View File

@ -10,6 +10,7 @@ class Element
{
public:
Element(){};
virtual ~Element(){}
virtual void accept(Visitor*) = 0;
void setPrice(int iPrice){
this->price = iPrice;

View File

@ -14,6 +14,7 @@ class Visitor
{
public:
Visitor(){};
virtual ~Visitor(){}
// 声明一组访问方法
virtual void visit(Apple*) = 0;
virtual void visit(Book*) = 0;