I have base class Item which store some data and grant access to it by accessors, like:

```
class Item{
  (...)
public:
  int get_value();
  double get_weight();
  ItemMaterial get_material();
  (...)
}

```

Then I've got derived classes like Weapon, Armor which add some additional data:

```
class Weapon : public Item {
(...)
public:
  int get_dmg();
  (...)
}

```

I store these Items in some container:

```
std::vector<Item*> inventory;

```

And here comes the problem with interface - how to get access to derived class data? I was thinking, and got 3 ideas:

**1. Separate interfaces**

Each derived class adds its data, like it is shown above, and then use dynamic\_cast:

```
Item *item = new Weapon;
int dmg = dynamic_cast<Weapon*>(item)->get_dmg();

```

**2. Common interface class**

Make an interface class with all accessors:

```
ItemInterface{
public:
  virtual int get_value() = 0;     //Item interface
  virtual double get_weight() = 0;
  (..)
  virtual int get_dmg() = 0;       //Weapon interface
  (...)
}

```

And then something like this:

```
Item : public ItemInterface{ (...) }

```

and

```
Weapon : public Item { (...) }

```

and finally we can access the data:

```
Item *item = new Weapon;
int dmg = item->get_dmg();

```

**3. Combination with templates and enums**

This idea is maybe a little weird :-) but:

implement enum with all item data:

```
enum class ItemData{
  Value,
  Weight,
  Material,  //Item data
  (...)
  Damage,    //Weapon data
  (...)
  Defense,   //armor data etc.
  (...)
  Null
}

```

and in base class some template function like this:

```
template<typename T>
T get_data(ItemData data){
  switch(data){
    case ItemData::Value: return _value; break;
    case ItemData::Damage: return _dmg; break;
    (...)
  }
}

```

and access data like:

```
Item *item = new Weapon;
ind dmg = item->get_data<int>(ItemData::Damage);

```

===

How do you think it should be done? I will be grateful for any advices!

Regards.