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

25 lines
516 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){
printf(" <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>%s, \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d, \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n", element->getName().c_str(), element->getNum());
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