I want to allow the player to buy as many items as he wants but only be able to equip a certain number of items. For that I have created a equipWeapon(Weapon *weap) function inside of Character.h
Now here is the issue.
I have some options for the user, if he wants to equip an item there will be an interface for it.
//user enters name of weapon he wishes to equip into string variable
//use that name in function ->
void Character::findWeapon(std::string name)//in Character.h
{
for(int i = 0; i < inventory.size(); i++)
if(inventory[i].getName() == name)
Item *ptr = &inventory[i]; //Base class pointer to object
Weapon<int> * weaponPtr = dynamic_cast<Weapon<int>* >(ptr);
//okay? here I'm having trouble, make that pointer point to
//derived weapon class object which it is
//the vector is simply used to store all items (instead of having
//multiple vectors)
EquipWeapon(weaponPtr); //call on class that actually equips the
//item and modifies the damage of the user
}
void Character::EquipWeapon(Weapon *weap) //but this doesn't work
{
dmg = 1 + (1.2 * str);
dmg += weap->getDmg();
}
I get an error on line 9 that says "weapon is not a template" and am unable to do anything after that. I hope I was clear in my question, please let me know if you need further information.
The error is highly descriptive. The Weapon class is not a template, so you cannot supply template parameters (the values inside the <>). You copied and pasted too faithfully from that example; you should replace Weapon<int> by simply Weapon as that is the name of the type.
I see, I'm sorry that is a silly mistake, I read the question on stack overflow and thought that was simply the way dynamic casts were done since I didn't see any int types inside of the question right away.