#include <iostream>
#include <string>
#include <vector>
using namespace std;
enum COMPONENT_TYPE {
ITEM,
BAG,
};
class Component {
private:
COMPONENT_TYPE type;
string name;
public:
Component(COMPONENT_TYPE t, string n) {
this->type = t;
this->name = n;
}
string getType() {
if (this->type == COMPONENT_TYPE::BAG) {
return "BAG";
}
else {
return "ITEM";
}
}
string getName() {
return this->name;
}
};
class Item : public Component {
public:
Item(string n) : Component(COMPONENT_TYPE::ITEM, n) {
}
};
class Bag : public Component {
public:
vector<Component>* contents = new vector<Component>();
Bag(string n) : Component(COMPONENT_TYPE::BAG, n) {
}
};
int main() {
Bag* outer = new Bag("big bag");
Item* item1 = new Item("sword");
Item* item2 = new Item("shield");
Bag* inner = new Bag("small bag");
outer->contents->push_back(*item1);
outer->contents->push_back(*item2);
outer->contents->push_back(*inner);
Item* item3 = new Item("food");
Item* item4 = new Item("potion");
inner->contents->push_back(*item3);
inner->contents->push_back(*item4);
std::cout << "Outer bag includes : " << std::endl;
for (Component i : *outer->contents) {
std::cout << i.getType() << " - " << i.getName() << std::endl;
}
std::cout << "Inner bag includes : " << std::endl;
for (Component i : *inner->contents) {
std::cout << i.getType() << " - " << i.getName() << std::endl;
}
return 0;
}