Original Post
Hey, I have used enum to set different weapon types. Now, the following code SHOULD return the weapon type to PTYPE weapon... but when I'm displaying it, all it shows is -84010201 or the likes..
here's the code.
#include <iostream>
enum PTYPE { Glock, Deagle, Magnum };
bool ERROR = false;
bool fQuit = false;
class BaseWeapon
{
public:
virtual void SetDamage(int a);
virtual int GetDamage();
protected:
int itsDamage;
};
int BaseWeapon::GetDamage()
{
return itsDamage;
}
void BaseWeapon::SetDamage(int a)
{
a = itsDamage;
}
class Pistol : public BaseWeapon
{
public:
PTYPE GetPistolType();
int ShootWeapon();
PTYPE GetWeapon() { return itsType; }
protected:
PTYPE itsType;
};
PTYPE Pistol::GetPistolType()
{
std::cout << "(1)Glock (2)Deagle (3)Magnum (0)Quit: " << std::endl;
for (;;)
{
int temp;
std::cin >> temp;
switch (temp)
{
case 1:
{
PTYPE itsType = Glock;
break;
}
case 2:
{
PTYPE itsType = Deagle;
break;
}
case 3:
{
PTYPE itsType = Magnum;
break;
}
case 0:
{
bool fQuit = true;
break;
}
default:
{
ERROR = true;
std::cout << "Please enter a valid argument: " << std::endl;
break;
}
}
if (ERROR == true)
continue;
else
break;
}
return itsType;
}
int main()
{
std::cout << "You are walking around and you see a ... gun, ";
std::cout << "they are a Glock, Magnum and Deagle, which one do you choose?" << std::endl;
Pistol *pPistol = new Pistol;
PTYPE weapon;
weapon = pPistol->GetPistolType();
std::cout << "weapon: " << weapon << std::endl;
return 0;
}
[edited by - ThomasSauder on October 12, 2003 11:39:26 PM]