Skip to main content
gamedev.net
🔒 Locked

Class problems

Started by Rasmadrak Mar 20, 2004 at 9:04 AM 12 replies 650+ views
Original Post
Rasmadrak
Rasmadrak
Hi there! I´m wondering if someone could help me with a problem I´m having. class thing : public weapon { public: //list of integers,floats,functions etc.. private: }; class weapon { public: //list of integers,floats,functions etc.. void GiveWeapon(int nr); private: }; //instead of doing this.... void weapon::GiveWeapon(int nr) { Strength = WeaponSystems[nr]->Strength; Range = WeaponSystems[nr]->Range; ReloadTime = WeaponSystems[nr]->ReloadTime; TimeToReload = WeaponSystems[nr]->TimeToReload; Type = WeaponSystems[nr]->Type; MaxAmmo = WeaponSystems[nr]->MaxAmmo; CurrentAmmo = WeaponSystems[nr]->CurrentAmmo; Name = WeaponSystems[nr]->Name; }; //I would want something similar to this... void weapon::GiveWeapon(int nr) { "self" = WeaponSystems[nr]; }; ...where "self" is a member of "thing", i.e weapon... Hope someone understands what I mean... =) Thanx for any help!! regards; Robert "Game Maker For Life, probably never professional thou." =)
"Game Maker For Life, probably never professional thou." =)
nhatkthanh
nhatkthanh
the way that you have it now is that weapon is a super class and thing class derive from weapon. What you want is to make thing the base class then have weapon derive from it, then you can do "self" = weapon object.
Rasmadrak
Rasmadrak
Well, my base class is thing... =)

weapon is a subclass in thing, if that''s what u meant?
"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
I would want it to be somewhat like this...

void weapon::GiveWeapon(int nr)
{
= WeaponSystems[nr];
};


"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
oh... wait...


doh!!

:D




everything went fine once I started using my brain... :D
I just removed the "=" and it worked...

thanx anyway!! :D
"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
hehe...

I must be dehydrated or something today... just because it compiled doesn''t mean it works, right? =S


well, back where I started...
any ideas?
"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
please?

Can somebody help me with this??

I''m out of ideas....




"Game Maker For Life, probably never professional thou." =)
"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
I got this....



class thing :
public weapon,
public body
//...
{
//....

};


Isn't thing the main class then?? =/



Yes, I believe that is what I want to do... but when I type "this = WeaponSystems[nr];" is says "Assignment to 'this' is not allowed, use X::operator new instead"


[edited by - Rasmadrak on March 20, 2004 12:41:38 PM]
"Game Maker For Life, probably never professional thou." =)
Rasmadrak
Rasmadrak
Ok.. =)

but i want all items to be "things", since then I could use


for (int i=0; i < 10000;i++)
Things[ i ]->Draw();


I found out that I can use following code instead;

void weapon::GiveWeapon(int nr)
{
WeaponStrength = WeaponSystems[nr]->WeaponStrength;
WeaponRange = WeaponSystems[nr]->WeaponRange;
WeaponReloadTime = WeaponSystems[nr]->WeaponReloadTime;
WeaponTimeToReload = WeaponSystems[nr]->WeaponTimeToReload;
WeaponType = WeaponSystems[nr]->WeaponType;
WeaponMaxAmmo = WeaponSystems[nr]->WeaponMaxAmmo;
WeaponCurrentAmmo = WeaponSystems[nr]->WeaponCurrentAmmo;
NameWeapon = WeaponSystems[nr]->NameWeapon;
};


this works, but is more awkward than the version I had in mind.... if I add a variable to the weapon class, I have to add the variable in the "GiveWeapon()" too.... well well, not a big problem.. just awkward.. =)


thanks for your time anyway!!




[edited by - Rasmadrak on March 20, 2004 1:03:25 PM]
"Game Maker For Life, probably never professional thou." =)
Kaezin
Kaezin
You can still do

for (int i=0; i < 10000;i++)
Things[ i ]->Draw();


With this method...

Look more into class inheritance and you should understand why Weapon and Armor should inherit from Thing rather than the other way around.
Half the people you know are below average.Trogdor the Burninator
psamty10
psamty10
Kaezins right, your current system has ''thing'' as a subclass of ''weapon'', not the other way round. Youd definitely want it to be:

class thing
{
// common members to all classes
// + common virtual functions (eg:virtual void Draw())
}

class weapon: public thing
{
// implementation
}
Rasmadrak
Rasmadrak
Ok, =)

I think I got this now...
Right now I got it like this...

class physics
{
public:
//lots of physics stuff
private:
};

class things :
public physics
{

weapon *Weapon;

};



will it be possible to change the weapon by doing this:

Things[ i ]->Weapon = ListOfWeapons[ 5 ];

?

I''m not at home right now, so I cant check it myself...
Eager to know! :D

thanx for your help! I''m a total newb to classes, especially with inheritance and such... I''ve been using structs before.. =)

/Robert

"Game Maker For Life, probably never professional thou." =)
"Game Maker For Life, probably never professional thou." =)

Topic Locked

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

Sign in to reply to this topic.