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." =)
🔒 Locked
Class problems
Advertisement
Original Post
Hi there!
I´m wondering if someone could help me with a problem I´m having.
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.
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]
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]
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]
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]
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
}
class thing
{
// common members to all classes
// + common virtual functions (eg:virtual void Draw())
}
class weapon: public thing
{
// implementation
}
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." =)
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." =)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement