• Advertisement
Sign in to follow this  

Pointer to an object

This topic is 4295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement