Classes

Started by
15 comments, last by briktal 22 years, 4 months ago
quote:Original post by briktal
I have a class which uses, say, test.GetStr() to get the character Test1''s strength. How can I use a variable, like "attacker" instead of "test" to do that?

--www.edf-project.org--


please include more details.. i mean how u declare the test object.

-damn the neighbours-
Advertisement
quote:Original post by briktal
I need information from another class in that function. Is there a better way to do this?


r u sure that u defined string class in header which is visible to ur class

-damn those stupid dogs-
maybe u should post all the code pertaining to the class so we can help better

"Those who serve no purpose, have no purpose"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
I have a class, Hero. I then did "Hero test;" and "Hero test2;" They have a number of stats, with functions to set and retrieve them ( int GetStr(), void SetStr(int str) ) One function has test attack test2. To do this, I need some stats from each of the Heroes. I want to be able to use some kind of variable to determine which Hero is attacking, and which is being attacked, so I can get the appropriate stats. Right now, I am just trying to find a way to use a variable, attacker, instead of test, to call test.GetStr(). I would like to know if there is a better way to do all of this.
--www.edf-project.org--
u can have a function like this
suppose u already have a function called: GiveDmg()

void Battle( Hero* enemy)
{
hp-=enemy->GiveDmg();
}


this is the simplest way i can think of at the moment
correct my if im wrong here ppl

"Those who serve no purpose, have no purpose"

Edited by - SonShadowCat on December 11, 2001 10:36:15 PM
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
quote:Original post by briktal
I have a class, Hero. I then did "Hero test;" and "Hero test2;" They have a number of stats, with functions to set and retrieve them ( int GetStr(), void SetStr(int str) ) One function has test attack test2. To do this, I need some stats from each of the Heroes. I want to be able to use some kind of variable to determine which Hero is attacking, and which is being attacked, so I can get the appropriate stats. Right now, I am just trying to find a way to use a variable, attacker, instead of test, to call test.GetStr(). I would like to know if there is a better way to do all of this.


Ok, someone already asked you but for some unknown reason, maybe you didn''t understand, post some code and then we will help you. In other words, post your class declaration at least so we can see what you''re actually trying to do...



"And that''s the bottom line cause I said so!"

** I WANT TO BE THE MODERATOR FOR THE LINUX FORUM **

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
[Cyberdrek | ]
quote:Original post by briktal
I have a class, Hero. I then did "Hero test;" and "Hero test2;" They have a number of stats, with functions to set and retrieve them ( int GetStr(), void SetStr(int str) ) One function has test attack test2. To do this, I need some stats from each of the Heroes. I want to be able to use some kind of variable to determine which Hero is attacking, and which is being attacked, so I can get the appropriate stats. Right now, I am just trying to find a way to use a variable, attacker, instead of test, to call test.GetStr(). I would like to know if there is a better way to do all of this.


create numerical ID in hero class, then u refer to that ID to determine which person is attacking. its that simple.

-damn the compiler-

This topic is closed to new replies.

Advertisement