954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Modifing Class Data through a Class Function

Hello,
What I am trying to do is edit the variable of a class through a separate class function. I have tried to do things like

int player::attack(int *enemy)
{
     srand(time(NULL));
     int randomNumber = rand() % 100;
     *consolePlayer.health = *consolePlayer.health - randomNumber;
}

and I get the error of :
`consolePlayer' undeclared (first use this function)

I know the anser is probably something I've accidentally overlooked, but could you please help?
Thank You,
EpicAsian

epicasian
Junior Poster in Training
53 posts since Nov 2009
Reputation Points: 12
Solved Threads: 0
 

Nevermind, I found an alternative that uses pointers.

epicasian
Junior Poster in Training
53 posts since Nov 2009
Reputation Points: 12
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You