Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Classes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 briktal   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 02:52 PM

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

Sponsor:

#2 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 11 December 2001 - 02:55 PM

Well, you just create a variable named attacker which is of the right type...

#3 SonShadowCat   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 02:56 PM

wat he said

like type this:

test* attacker= new test;

done

Edited by - SonShadowCat on December 11, 2001 9:56:52 PM

#4 briktal   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 02:59 PM

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

#5 Cyberdrek   Members   -  Reputation: 100

Like
Likes
Like

Posted 11 December 2001 - 03:02 PM

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

#6 SonShadowCat   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:04 PM

maybe i should have said that too ~.~

"Those who serve no purpose, have no purpose"

#7 briktal   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:10 PM

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

#8 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 December 2001 - 03:13 PM

u should be clear next time

-anynomous poster-

#9 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 11 December 2001 - 03:15 PM

err.. if you have created a class, why aren''t you using it ? Why use a string ?

#10 briktal   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:15 PM

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

#11 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 December 2001 - 03:20 PM

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-

#12 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 December 2001 - 03:27 PM

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-

#13 SonShadowCat   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:27 PM

maybe u should post all the code pertaining to the class so we can help better

"Those who serve no purpose, have no purpose"

#14 briktal   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:28 PM

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.

#15 SonShadowCat   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 December 2001 - 03:35 PM

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

#16 Cyberdrek   Members   -  Reputation: 100

Like
Likes
Like

Posted 11 December 2001 - 03:36 PM

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

#17 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 December 2001 - 03:46 PM

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-




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS