我对异常类有疑问...“对 GameProject::GamePlayerNullPointerException::~GamePlayerNullPointerException 的未定义引用”
上线:throw GamePlayerNullPointerException();
游戏.h
#ifndef GAME_H
#define GAME_H
#include <iostream>
#include "Player.h"
#include "Platform.h"
#include "Item.h"
#include <exception>
#include <stdexcept>
#include <string>
#define string std::string
#define ostream std::ostream
#define istream std::istream
namespace GameProject {
class Game
{
public:
friend class Inner;
Game();
~Game();
void startNew();
void quit();
void pause();
void resume();
void update();
void moveLeft();
void moveRight();
int getScore();
protected:
private:
class Inner;
Inner *i;
Game(const Game& g);
};
class GameException : public std::exception{
private:
string error;
public:
GameException(const string& message ): error(message){};
~GameException()throw ();
virtual const char* what() throw ();/*const{
return error.c_str();
throw ();
}*/
};
class GameNullPointerException: public GameException{
public:
GameNullPointerException(const string & message)
: GameException(message ) {};
~GameNullPointerException() throw ();
};
class GamePlayerNullPointerException: public GameNullPointerException{
public:
GamePlayerNullPointerException(const string & message = "Player not exist!")
: GameNullPointerException( message )
{}
~GamePlayerNullPointerException() throw ();
};
class GamePlatformNullPointerException: public GameNullPointerException{
public:
GamePlatformNullPointerException()
: GameNullPointerException( "Platform not exist!" ){}
~GamePlatformNullPointerException() throw ();
};
class GamePlayerWrongPositionException: public GamePlayerNullPointerException{
public:
GamePlayerWrongPositionException(): GamePlayerNullPointerException( "Player off screen!!!" ){ }
~GamePlayerWrongPositionException() throw ();
};
}
#undef string
#undef ostream
#undef istream
#endif // GAME_H
游戏.cpp
void Game::startNew() {
if(i->pla==NULL)
throw GamePlayerNullPointerException();
i->pla = new Player(20,20);
i->init();
}
有任何想法吗?