Text Book Error Need Help!
Hi, I have spent three hours copying and learning a large program in OOP, but when I compiled it, I got this error:
Code:
Documents\C++\Haunt\main.cpp request for member `health' in `play', which is of non-class type `Player ()(int, int, int)'
I wont post all the code as it is very large, but here is the code that the class implelemnts.
The error is referining to the line in main that reads:
play.health++;
code from header file:
Code:
/******* player class *********************************************************/
class Player
{
public:
int m_Health;
int m_Magic;
int m_Gold;
Player( int health = 100, int magic = 1, int gold = 5 ); // constructor
~Player(); // deconstructor
private:
bool pdead; // is player defeated ( at start of play )
bool palive; // is player active ( at start of play )
};
code from class implemet file:
Code:
Player::Player( int health, int magic, int gold )
{
m_Health = health;
m_Magic = magic;
m_Gold = gold;
palive = true; // new game
pdead = false; // turns TRUE when player defeated
}
code from main:
Code:
void area1 ( void )
{
Player play( int health, int magic, int gold );
play.health++; // ERRPR LINE
}
It is the only compile error, and the book says on running, health should increase by one. I think the error is the line above the error line, but I am not sure. Please Help!