Misconception about classes?

This is a discussion on Misconception about classes? within the C++ Programming forums, part of the General Programming Boards category; I was under the impression that all the functions in a class shared the variables that were defined in the ...

Misconception about classes?

I was under the impression that all the functions in a class shared the variables that were defined in the class. Was I mistaken? My compiler keeps telling me that the variables in the class haven't been declared in the functions within the class that I use them in. So I guess I was wrong. If I am wrong, is there an easy way to solve this?

Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

That's rather strange. Your code looks correct, and compiles without errors on the MinGW port of g++ 3.4.5, MSVC8, and the online Comeau compiler. There should be no need to change it to robwhit's example. What compiler are you using?

Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Good for you, but I asked about compiler, not IDE. CodeBlocks might use g++, or perhaps a Microsoft compiler, or yet other compilers.

my example compiles fine...hmmm, I thought I included the problem, here is the full class

It is a good idea to test your examples before posting them
Anyway, I believe XSquared got it right.

That said, you may want to improve your class design a little. Trying to store everything about the player directly in the player class can be a little cumbersome. It may make sense to create other classes, e.g., armor and weapon classes.

Thanks for all the help, I got the problem fixed and understand what I did wrong.

Originally Posted by laserlight

]
That said, you may want to improve your class design a little. Trying to store everything about the player directly in the player class can be a little cumbersome. It may make sense to create other classes, e.g., armor and weapon classes.

I'll try to improve the organization, but I wanted there to be a separate function for the fighting, than there was for the scenario stuff.