使用枚举的奇怪 SIGSEGV(分段错误)
我目前收到一个非常奇怪的 SIGSEGV(分段错误),没有使用任何指针,只是枚举;这是我的代码:
typedef enum
{
LIGHT,
DARK,
NONE
} Color;
class Board
{
public:
Color toMove();
private:
Color side;
};
实现是:
Color Board::toMove()
{
return side;
}
我只是调用 toMove();
并导致分段错误;这是 gdb 输出:
Program received signal SIGSEGV, Segmentation fault.
0x004025ee in Board::toMove (this=0x0)
at ...\board.cpp:19
19 return side;
有人知道吗?
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 toMove();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自调试器的这个可爱提示 (
this=0x0
) 表明您尝试在没有有效Board
对象的情况下调用toMove()
。This lovely hint from your debugger (
this=0x0
) suggests you tried to calltoMove()
without a validBoard
object.this = 0x0
是线索:您在 NULLBoard
上调用toMove()
。不要这样做:-)The
this = 0x0
is the clue: you're callingtoMove()
on a NULLBoard
. Don't do that :-)