#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
// Item
class MyA { };
class MyB { };
enum MyTypeEnum
{
myAType,
myBType
};
class MyItem
{
public:
explicit MyItem(MyTypeEnum theType) : myType(theType) { };
void Print();
private:
MyTypeEnum myType;
};
void MyItem::Print()
{
if(myType == myAType)
cout << "MyItem - myA" << endl;
else if(myType == myBType)
cout << "MyItem - myB" << endl;
}
// ItemList
class MyItemList
{
public:
void AddItem(MyItem theItem);
void PrintItems();
private:
list<MyItem> myList;
};
void MyItemList::AddItem(MyItem theItem)
{
myList.push_back(theItem);
}
void MyItemList::PrintItems()
{
for_each(myList.cbegin(), myList.cend(), [](MyItem i)
{
i.Print();
});
}
// main
int main(int argc, char * argv[])
{
MyItemList itemList;
// itemList soll die Elemente tatsächlich besitzen
{
itemList.AddItem(MyItem(myAType));
itemList.AddItem(MyItem(myBType));
}
itemList.PrintItems();
return 0;
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGxpc3Q+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gSXRlbQpjbGFzcyBNeUEgeyB9OwpjbGFzcyBNeUIgeyB9OwoKZW51bSBNeVR5cGVFbnVtCnsKCW15QVR5cGUsCglteUJUeXBlCn07CgpjbGFzcyBNeUl0ZW0KewpwdWJsaWM6CglleHBsaWNpdCBNeUl0ZW0oTXlUeXBlRW51bSB0aGVUeXBlKSA6IG15VHlwZSh0aGVUeXBlKSB7IH07Cgl2b2lkIFByaW50KCk7Cgpwcml2YXRlOgoJTXlUeXBlRW51bSBteVR5cGU7Cn07Cgp2b2lkIE15SXRlbTo6UHJpbnQoKQp7CglpZihteVR5cGUgPT0gbXlBVHlwZSkKCQljb3V0IDw8ICJNeUl0ZW0gLSBteUEiIDw8IGVuZGw7CgllbHNlIGlmKG15VHlwZSA9PSBteUJUeXBlKQoJCWNvdXQgPDwgIk15SXRlbSAtIG15QiIgPDwgZW5kbDs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