In player.cpp, Player::getScore and Player::getHighScore return pointers to dealocated memory.
const char* Player::getHighscore()
{
std::string s = std::to_string(highscore);
s = "BEST: " + s;
return s.c_str();
}
const char* Player::getScore()
{
std::string s = std::to_string(score);
s = "DISTANCE: " + s;
return s.c_str();
}
When std::string s goes out of scope, the const char* that s.c_str returns is invalidated. Access to the underlying string may be garbage, cause a segfault, or cause other nasty issues.
In player.cpp, Player::getScore and Player::getHighScore return pointers to dealocated memory.
const char* Player::getHighscore() { std::string s = std::to_string(highscore); s = "BEST: " + s; return s.c_str(); }
const char* Player::getScore() { std::string s = std::to_string(score); s = "DISTANCE: " + s; return s.c_str(); }
When std::string s goes out of scope, the const char* that s.c_str returns is invalidated. Access to the underlying string may be garbage, cause a segfault, or cause other nasty issues.