bugfix: fix memory leak issue for ObserverPattern
parent
40a2c486d5
commit
fda85a8136
|
@ -3,24 +3,24 @@
|
|||
|
||||
/*********** AllyCenter ****************/
|
||||
AllyCenter::AllyCenter(){
|
||||
printf("大吉大利,今晚吃鸡!\n");
|
||||
printf("大吉大利,今晚吃鸡!\n");
|
||||
}
|
||||
|
||||
// 加入玩家
|
||||
// 加入玩家
|
||||
void AllyCenter::join(Observer* player){
|
||||
if (playerList.size() == 4){
|
||||
printf("玩家已满\n");
|
||||
printf("玩家已满!\n");
|
||||
return;
|
||||
}
|
||||
printf("玩家 %s 加入\n", player->getName().c_str());
|
||||
printf("玩家 %s 加入\n", player->getName().c_str());
|
||||
playerList.push_back(player);
|
||||
if (playerList.size() == 4){
|
||||
printf("组队成功,不要怂,一起上!\n");
|
||||
printf("组队成功,不要怂,一起上!\n");
|
||||
}
|
||||
}
|
||||
// 移除玩家
|
||||
// 移除玩家
|
||||
void AllyCenter::remove(Observer* player){
|
||||
printf("玩家 %s 退出\n", player->getName().c_str());
|
||||
printf("玩家 %s 退出\n", player->getName().c_str());
|
||||
//playerList.remove(player);
|
||||
}
|
||||
/*********** AllyCenter ****************/
|
||||
|
@ -31,7 +31,7 @@ AllyCenterController::AllyCenterController(){
|
|||
|
||||
}
|
||||
|
||||
// 实现通知方法
|
||||
// 实现通知方法
|
||||
void AllyCenterController::notify(INFO_TYPE infoType, std::string name){
|
||||
switch (infoType){
|
||||
case RESOURCE:
|
||||
|
|
|
@ -64,6 +64,9 @@ int main()
|
|||
Observer *obs = new ConcreteObserver();
|
||||
sub->attach(obs);
|
||||
sub->notify();
|
||||
|
||||
delete sub;
|
||||
delete obs;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue