Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Rasmadrak

Class problems

This topic is 5206 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

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." =)

Share this post


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

Share this post


Link to post
Share on other sites
oh... wait...


doh!!

:D




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

thanx anyway!! :D

Share this post


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

Share this post


Link to post
Share on other sites
please?

Can somebody help me with this??

I''m out of ideas....




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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Again, like nhatkthanh said, in your example, ''weapon'' is your base class, and you have ''thing'' inheriting from it. When you''ve got this:

class thing : public weapon

''thing'' is going to inherit from ''weapon'', not the other way around, which is what it sounds like you''re trying to do.

If I understand correctly (and I may not be), you''ll want to replace "self" with "this". The object that calls GiveWeapon will then be pointing to the WeaponSystems[nr] object. In this case, any changes that are made to index nr of WeaponSystems will also change the object that called GiveWeapon. This is because both are pointing to the same memory location.

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m afraid not. This:

class thing :
public weapon,
public body

will cause ''thing'' to inherit from both ''weapon'' and ''body''. I believe what you''re trying to do is:

class thing
{
// base properties for all objects
}

class weapon : public thing
{
// properties for weapons
}

class armor : public thing
{
// properties for armor
}

Here, ''thing'' will be your base object, and should contain everything that will be common for every type of item (location, weight, etc.). Then, more specific item types (such as weapons or armor) will inherit from ''thing'', and contain all of ''thing''s properties.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!