シングルトン クラスの静的メンバー関数内では、getInstance() を使用する代わりに、静的ポインター メンバー変数を直接使用しました。
null チェックを行わず、実行時に null だったため、null ポインター例外が発生しました。
PC lint はこれを通知しませんでした。通常、Prio 2 警告として通知されます: null ポインターの使用の可能性。
なぜ私に通知しなかったのですか?
class stClass
{
int m_value;
static stClass *s_instance;
stClass(int v = 0)
{
m_value = v;
}
public:
int get_value()
{
return m_value;
}
void set_value(int v)
{
m_value = v;
}
static stClass *getInstance()
{
if (!s_instance)
s_instance = new stClass;
return s_instance;
}
static void intentFunction()
{
printf("%d", s_instance->getValue()); // Null pointer exception here...
}
};