Archived

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

briktal

Classes

Recommended Posts

briktal    122
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--

Share this post


Link to post
Share on other sites
briktal    122
I tried that, but I get an error that the variable does not have a member function GetStr() defined, or something like that.

--www.edf-project.org--

Share this post


Link to post
Share on other sites
Cyberdrek    100
quote:
Original post by briktal
I tried that, but I get an error that the variable does not have a member function GetStr() defined, or something like that.

--www.edf-project.org--


Try using this:

attacker->GetStr();

if you dynamicly create an instance of a class, you have to use the -> to call your member functions...





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

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

Share this post


Link to post
Share on other sites
briktal    122
I used that, it seems to help, but does not appear to work if "attacker" is a string. It says something to the effect of cannot use -> with non-pointer type string.

--www.edf-project.org--

Share this post


Link to post
Share on other sites
briktal    122
About what?

I get an error: " base operand of '->' has non-pointer type 'string' "

Is there another variable type I should use?

--www.edf-project.org--

_____EDIT_____
I need information from another class in that function. Is there a better way to do this?

Edited by - briktal on December 11, 2001 10:17:30 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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-

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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-

Share this post


Link to post
Share on other sites