Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ PC Lint未检测到在静态成员指针变量上可能使用空指针_C++_Pointers_Lint_Pc Lint - Fatal编程技术网

C++ PC Lint未检测到在静态成员指针变量上可能使用空指针

C++ PC Lint未检测到在静态成员指针变量上可能使用空指针,c++,pointers,lint,pc-lint,C++,Pointers,Lint,Pc Lint,在单例类的静态成员函数中,我没有使用getInstance(),而是直接使用静态指针成员变量 我并没有对它进行null检查,它在运行时为null,因此出现null指针异常 PC lint没有通知我这件事。通常它会以Prio 2警告的形式通知我:可能使用空指针 为什么不通知我 class stClass { int m_value; static stClass *s_instance; stClass(int v = 0) { m_value =

在单例类的静态成员函数中,我没有使用getInstance(),而是直接使用静态指针成员变量

我并没有对它进行null检查,它在运行时为null,因此出现null指针异常

PC lint没有通知我这件事。通常它会以Prio 2警告的形式通知我:可能使用空指针

为什么不通知我

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...
    }
};

对于pc lint人员来说,也许是一个更好的问题(或错误报告?)?OTHH,可能有C++解释。也许是因为他们认为你有一个合乎逻辑的答案。@ WoZrigar,但我不调用静态成员函数。