DesignPattern/24.VisitorPattern/2.Code/ShoppingCart.h

25 lines
531 B
C
Raw Normal View History

2019-11-10 14:59:08 +00:00
#ifndef __SHOPPINGCART_H__
#define __SHOPPINGCART_H__
#include "Element.h"
#include "Visitor.h"
#include <vector>
class ShoppingCart
{
public:
ShoppingCart(){}
void addElement(Element* element){
2021-10-28 15:15:51 +00:00
printf(" 商品名:%s, \t数量:%d, \t加入购物车成功!\n", element->getName().c_str(), element->getNum());
2019-11-10 14:59:08 +00:00
elementList.push_back(element);
}
void accept(Visitor* visitor){
for (int i = 0; i < elementList.size(); i++){
elementList[i]->accept(visitor);
}
}
private:
vector<Element*>elementList;
};
#endif