我已经为我正在开发的一个小C++项目创建了一个有限状态机类,但由于某种原因,程序一旦达到某个if语句就会段错误.
这是班级本身:
class FiniteStateMachine
{
protected:
void cleanup();
State* state_;
public:
FiniteStateMachine();
FiniteStateMachine( State* const state );
~FiniteStateMachine();
void changeState();
void forceState( State* const state );
char const* getStateName();
};
Run Code Online (Sandbox Code Playgroud)
在定义中,程序一旦到达条件语句就会段错误:
void FiniteStateMachine::changeState()
{
debugging("FiniteStateMachine::changestate() called");
if( state_ ) // problem point
{
debugging("state_ is not nullptr");
// state_.handle();
}
else
{
debugging("state_ is nullptr");
}
}
Run Code Online (Sandbox Code Playgroud)
debugging()只是一个用于在调试模式下向stdout显示消息的函数.对我来说最奇怪的事情是如果(state_)在程序的早期使用没有任何障碍.
我正在使用gcc版本4.9.2,Linux Mint 17.2和C++ 11
如果您需要任何进一步的细节,这里是github存储库的链接.