Pointer to an object

Started by
3 comments, last by izhbq412 17 years, 11 months ago
I am making a 3D FPS, and I need a way to make a pointer to my weapon objects. How can I make a pointer class, so when I type CurrentGun.Shoot(); it shoots the gun set by CurrentGun = AssaultRifle;
Advertisement
inheritance virtual function

Kuphryn
This will get you started.

class BaseGun{    virutal int Shoot();}class AssaultGun : public BaseGun{}AssaultGun::Shoot(){    //.. Take care of your shooting...}


Hope this helps.
theTroll

[Edited by - Fruny on May 19, 2006 8:18:39 PM]
Sort of, Im a little confused.

I have one class named Gun.

I am creating CurrentGun and AssaultRifle.

I always used CurrentGun for actions like shoot.
I need it to update and keep values for AssaultRifle.
Is AssaultRifle a class or an object? CurrentGun is supposed to be a pointer to any weapon, right?

Gun* pCurrentGun = &AssaultRifle
pCurrentGun->Shoot();

Where AssultRifle's class inherits from Gun and Gun's Shoot method is virtual.

If that's not what you want, please clarify (What classes and objects do you have?).
_______________The essence of balance is detachment. To embrace a cause, to grow fond or spiteful, is to lose one''s balance after which, no action can be trusted. Our burden is not for the dependent of spirit. - Mayar, Third Keeper

This topic is closed to new replies.

Advertisement