int main() { //ConcreteAggregate *pName = NULL; ConcreteAggregate *pName = new ConcreteAggregate(); if(NULL != pName) { pName->Push("Hello"); pName->Push("word"); pName->Push("kevin"); } Iterator *iter = NULL; iter = pName->CreateIterator(); if(NULL != iter) { string strItem = iter->First(); while(!iter->IsEnd()) { cout << iter->GetCur() << " is ok " << endl; iter->Next(); } } delete pName; return 0; }
int main() { ConcreteAggregate<int> a; a.PushBack(1); a.PushBack(2); a.PushBack(3); a.PushBack(4); Iterator<int> *iter = a.CreateIterator(); iter->First(); while(iter->IsDone() == false) { std::cout << iter->CurrentItem() << std::endl; iter->Next(); } return 0; }
int main() { ConcreteAggregate *a = new ConcreteAggregate(); a->addItem(5); a->addItem(4); a->addItem(3); a->addItem(2); a->addItem(1); Iterator *i = a->createIterator(); while (!i->isDone()) { cout << i->next() << endl; } return 0; }