当代码 rey 指向 NULL 指针时,我在调试器中遇到分段错误错误。
这个函数做错误:
void Player::nullActive()
{
activeCharacter = NULL;
}
activeCharacter 只是 Character 类的一个指针。
另外,这是播放器类:
class Player
{
public:
Player(unsigned int accID, std::string aID, bool isBanned); //constructor, allow only create object id-s one time
~Player();
std::string getAtheriusID(); //return account id
unsigned int getAccountID(); //return atherius id
boost::ptr_vector<Character> characters;
bool isBanned();
bool hasActiveCharacter();
void nullActive();
void setActiveCharacter(Character * character);
void setConnection(CSConnection * con);
CSConnection * getConnection();
Character * getActiveCharacter();
unsigned int atheriusCoins;
protected:
unsigned int accountID; //account unique id
std::string atheriusID; //account name / atherius id
bool banned;
private:
CSConnection * connection;
Character * activeCharacter = NULL;
};
和调试器的输出:
程序收到信号 SIGSEGV,分段错误。在 F:\EternalHeroes\server\src\game\src\Player.cpp:36 继续... 程序收到信号 SIGSEGV,分段错误。在 F:\EternalHeroes\server\src\game\src\Player.cpp:36 继续... [Inferior 1 (process 11552) exited with code 030000000005] 调试器以状态 0 完成