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." =)
Class problems
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 would want it to be somewhat like this...
void weapon::GiveWeapon(int nr)
{
= WeaponSystems[nr];
};
void weapon::GiveWeapon(int nr)
{
= WeaponSystems[nr];
};
oh... wait...
doh!!
:D
everything went fine once I started using my brain... :D
I just removed the "=" and it worked...
thanx anyway!! :D
doh!!
:D
everything went fine once I started using my brain... :D
I just removed the "=" and it worked...
thanx anyway!! :D
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?
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?
please?
Can somebody help me with this??
I''m out of ideas....
"Game Maker For Life, probably never professional thou." =)
Can somebody help me with this??
I''m out of ideas....
"Game Maker For Life, probably never professional thou." =)
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.
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]
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement