   Inventory
  HiyaI have an inventory which is vector of "*Item"s. Then all the various item types are derived from this (Weapon, Shield and so on), how would I be able to access a Weapon only variable from the vector?   
  First of all, what language are you using?In C# you would do something like this:foreach (Item item in inventory){   if (item is Weapon)   { // Do stuff   }}Although i think the equivalent of vectors in C# are ArrayLists/Lists.   ;  If I understand ya properly, you should take a look into iterators (for vector scanning) and then add a function to your item class to return it's type for checking if it's a weapon.   ;  just a minor additional pointIf you wanted to use it as a weapon after determining it is one you will need to type cast itin c#:foreach (Item item in inventory){   if (item is Weapon)   { (item as Weapon).whatever(); // Do stuff   }}*edit* corrected source tags   ;  I assume you're using C++, but I don't know of anything native to the language.  Perhaps like Aternus said you could have an id in the base item and change that value for each derived type so you know what you're looking for.I did something similar to this once.  I had an id variable in the base class and in the constructor of the derived class altered the value depending on the type it was.  It seemed to work out alright.  All of this is assuming i'm understanding what you want to do exactly [smile].   ;  You could use a dynamic_cast.Something like this:Item* yourObject; //this is a pointer to the object to test which class it belongs toWeapon * weapon = dynamic_cast<Weapon *>(yourObject);Shield * shield = dynamic_cast<Shield *>(yourObject);if(weapon){// object is of class Weapon};  assuming your using C++, there are two easy solutions to this:one, as mentioned earlier, is just to add a tag (I suggest an enumeration) to your base class to identify each item:enum ItemType{WEAPON, SHIELD, POTION};class Item:{private:ItemType type;...public:ItemType getType() {  return type;}...}...std::vector<*Item> items;for (std::vector<*Item>::iterator it = items.begin(); it != items.end(); ++it){  switch((*it)->getType())  {    case WEAPON:    weapon* pWeapon = reinterpret_cast<weapon*>(*it);    //do weapon stuff    break;   ...  }}the other solution, which may or may not fit what your trying to do, would be to make a virtual use() function in your base class, and have each inherited class provide their own version of it. that way, you could go through your vector and just use() each item, without need for knowing what type each item is and without using casts.edit: after re-readiong your original post, i don't think the virtual function way of doing things is what your looking for.   ;  You may also consider keeping the separately-typed things in separate containers instead.struct Inventory {  std::vector<Weapon> weapons;  std::vector<Armour> armours;  // etc.};There is no "best solution" here universally; it depends on the totality of your usage patterns. Various different ways of organizing things will make certain tasks easier or cleaner at the expense of others.   