0

例外クラスに問題があります..."GameProject:: GamePlayerNullPointerException ::〜GamePlayerNullPointerExceptionへの未定義の参照"

オンライン:GamePlayerNullPointerException();をスローします。

Game.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

Game.cpp

void Game::startNew() {
if(i->pla==NULL)
    throw GamePlayerNullPointerException();
i->pla = new Player(20,20);
i->init();
}

何か案は?

4

1 に答える 1

2
~GamePlayerNullPointerException() throw ();

デストラクタを宣言しましたが、定義していません。宣言を.hファイル内の定義に変更します。

~GamePlayerNullPointerException() throw () { }

または、.cppファイルに定義を追加します。

GamePlayerNullPointerException::~GamePlayerNullPointerException() throw ()
{
}

または、何もしない場合はそれを取り除きます。空のデストラクタを指定しない場合、コンパイラは空のデストラクタを生成します。

于 2012-12-19T20:08:53.763 に答える