Classes

Started by
15 comments, last by briktal 22 years, 4 months ago
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--
--www.edf-project.org--
Advertisement
Well, you just create a variable named attacker which is of the right type...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
wat he said

like type this:

test* attacker= new test;

done

Edited by - SonShadowCat on December 11, 2001 9:56:52 PM
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
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--
--www.edf-project.org--
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
[Cyberdrek | ]
maybe i should have said that too ~.~

"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 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--
--www.edf-project.org--
u should be clear next time

-anynomous poster-
err.. if you have created a class, why aren''t you using it ? Why use a string ?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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
--www.edf-project.org--

This topic is closed to new replies.

Advertisement