So, I am making a small game in C ++, and I ran into a problem. I have a class called a player inside my player.h file, and inside this class I have a public getPotion() function. I also have a static variable called potion . I have the same thing for player health, and the getHealth() function perfectly returns the private static int playerHealth . But apparently there is no reason, the getPotion function getPotion not return the potion. Instead, I get an error message. I also included the header file in all my other files.
Here is the code:
(Sorry, I don't know how to embed code, so I have to write it)
player.h (the code I'm having problems with):
class Player{ private: static int potions; public: int getPotions(); }
player.cpp (again, the code I came across):
int Player::potions; int Player::getPotions(){ Player player; return player.potions; }
I probably forgot some pieces of code, such as return, etc., but this is because I have a small amount of time to ask this question, so I put the parts related to my problem.
source share