Skip to main content
gamedev.net
🔒 Locked

Pointer to an object

Started by Fixxer 3 replies 550+ views
Original Post
Fixxer
Fixxer
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;
kuphryn
kuphryn
inheritance virtual function

Kuphryn
TheTroll
TheTroll
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]
Fixxer
Fixxer
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.
izhbq412
izhbq412
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.