开发者

Weird SIGSEGV (Segmentation fault) using enums

I'm currently getting a very wierd SIGSEGV (Segmentation fault), not using any pointers that is, just enums; this is my code:

typedef enum 
{
    LIGHT,
    DARK,
    NONE
} Color;

class Board
{
    public:
        Color toMove();
    private:
        Color side;
};

and the implementation is:

Color Board::toMove()
{
    return side;
}

And I'm simply calling toMov开发者_Go百科e(); with results in the segmentation fault; here's gdb output:

Program received signal SIGSEGV, Segmentation fault.
0x004025ee in Board::toMove (this=0x0)
    at ...\board.cpp:19
19          return side;

Anyone got an idea?


This lovely hint from your debugger (this=0x0) suggests you tried to call toMove() without a valid Board object.


Board::toMove (this=0x0)

The this = 0x0 is the clue: you're calling toMove() on a NULL Board. Don't do that :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜