   Quite simple C++ Class question
  Hey!So I have been trying to split my code into several files and using headers to declare the classes and then define them in a source file. The problem is in the Source file I can access all the public functions and define them nicely, but I am not able to use the private variables inside those functions. How can you solve this?I have tried reading the tutorial on GameDev.net, which was really nice, but still get this error.I get the following error: Quote:c:\users\johan\documents\visual studio 2008\projects\oop_test\oop_test\player.cpp(8) : error C2065: 'health' : undeclared identifier1>c:\users\johan\documents\visual studio 2008\projects\oop_test\oop_test\player.cpp(14) : error C2065: 'health' : undeclared identifierMy code is:Player.hQuote:#ifndef _PLAYER_H#define _PLAYER_Hclass Player{public:void set_health(int amount); // Public set functionint get_health(); // Public get functionprivate:int health;};#endifPlayer.cppQuote:#include "Player.h"// MY PLAYER CLASS// define our set functionvoid set_health(int amount){health = amount;}// define our get functionint get_health(){return health;}main.cppQuote:#include "Player.h"#include <iostream>using namespace std;/* Main function */int main(){Player player1;cout << "MAIN FUNCTION" << endl;cout << "Creating class: Player" << endl;player1.set_health(10);cout << "Player health: " << player1.get_health();int dummy;cin >> dummy;}I guess it is something really simple, tried googling and everything for hours without a good answer :P   
  In player.cpp, the line:void set_health(int amount)Should be:void Player::set_health(int amount)And the line:int get_health()Should be:int Player::get_health()Currently you're declaring get_health and set_health as free standing functions in player.cpp, so the compiler is looking for the "health" variable at global or function scope, it doesn't know you mean it's the Player classes member variable you're referring to. The Player:: prefix tells the compiler that these are Player member functions.   ;  Hi,The error is in player.cppWhen implementing your class methods, they need the "scope" they're in.so...your set_heath method for example should be implemented like this:void Player::set_health(int amount){  health = amount;}Edit: gah, EvilSteve already answered it :)   ;  Oh god...Thank you so much. I was almost certain I tried that, but obviously not. Again thank you for your fast reply!   ;  Why would you ever want to set the health from outside the player class? Shouldn't said class be responsible for changing the health through functions like take_damage, drink_potion et cetera?   