This is my current code of the class Score in the Score.h file:-
class Score
{
protected:
long m_Scores;
long m_HighScore;
//private:
public:
Score();
~Score();
void Init();
void Update(float deltaMS);
void Render();
void Release();
void SetScore(long sc){
m_Scores=sc;
}
long GetScore(){
return m_Scores;
}
void SetHighScore(long sc){
m_HighScore=sc;
}
long GetHighScore(){
return m_HighScore;
}
void AddScore(int add);
};
I am getting the following error whenever I try to access m_Scores in the class itself.
Access violation writing location 0xaaaaaaaa.
The SetScore() method can’t be run due to this.
I know I am doing something silly, but couldn’t figure it out. Can you please help me out.
It happens because your
Scoreobject that you try to SetScore() is already outdated, destoryed. Pay attention to its lifetime.