Okay, I'm making a shooter game, and all my weapons are differnt userdefined objects; ie. the flamethrower works differently then the gun, however, I'm calling some functions in my "main", an example of this would be;
/* <Init> */ MachineGunClass *CurrentWeapon; MachineGunClass *MachineGun; MachineGun = new MachineGunClass(); CurrentWeapon = MachineGun; /* </Init> */ /* <Usage> */ /* Lots of code */ CurrentWeapon->Shoot(); /*More code */ /* </Usage> */
So this works as it should, however let's say I wanted to use my flamethrower, to change to that weapon I would call the following;
FlameThrowerClass *FlameThrower; FlameThrower = new FlameThrowerClass(); CurrentWeapon = FlameThrower;
However this ofc, wont work, but wouldn't it work if I changed CurrentWeapon to a void pointer, and then typecasted that, on each weapon change? - Wouldn't that be possible, and really is there any good guides on typecasting?
Thanks in advance!