I'm trying to make the weapon pointer point to an Item, but it can't, even though Weapon is a specific type of Item. |
Note that the following assumes public inheritance.
It can't,
because a weapon is a specific type of item. How do we know a weapon is a kind of item? Because everything you can do to an item (i.e. all functions and members), you can do to a weapon.
Weapon inherits from item. Thus, all weapons are also items. Are all items weapons? No. Some could be players, some could be plain items, some could be something else. Are we sure? Well, there are things you can do to a weapon (i.e. all functions and members) that you cannot do to an item - the extra things weapon has alongside the inherited parts. So clearly items are not weapons.
If you have a weapon pointer, it must point at something that is a weapon. Is a weapon a weapon? Yes. So it can point at a weapon. Is an item a weapon? No, as discussed above. So a weapon pointer can only point at a weapon.
If you have an item pointer, it must point at an item. Is a weapon an item? Yes, as discussed above. Is an item an item? Yes. Is a player an item? Yes. So the item pointer can point at all of these.
The key point is that all items are not weapons, so you cannot make a weapon pointer point at an item.