Sign in to follow this  
Fixxer

Pointer to an object

Recommended Posts

Fixxer    100
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
TheTroll    883
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
Fixxer    100
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
izhbq412    204
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this