未处理的异常 - 访问冲突读取位置 0x00000000

Unhandled exception - Access violation reading location 0x00000000

我有三个类和一个函数,它在代码中的某个地方运行良好,如果我把它放在其他地方就会崩溃,我想不通为什么会这样。很乐意指导。

class BaseClass
{
    friend class B;

protected:
    string m_name;

    BaseClass::BaseClass();                 // implementation doesn't matter
    virtual bool execute  (SRV *p_Srv) = 0;
    virtual void setName(string name)
    {
      m_name = name;
    }
    ~BaseClass(void);               // implementation doesn't matter
};


class derivedClass:public BaseClass
{
    friend class B;

protected:
    derivedClass(void);                 // implementation doesn't matter
    bool execute (SRV *p_Srv);          // implementation doesn't matter
    ~derivedClass(void);                // implementation doesn't matter
};


class B
{
    BaseClasse **array;
    string twoDimArray[2][MAX_PARAMS_SIZE];

    bool function()
    {
     ....
     p_pipeline[i] = new derivedClass(twoDimArray);
     ** EDIT: array[i]->setName("name"); **             <------ problematic line
     p_pipeline[i]->setName("name");                  <------ problematic line
     if (checkIfNewFilterCreated(i, "name") == "-1")                                                    
        throw msg;
     ....
    }

 string B::checkIfNewFilterCreated(int index, string name)
 {
     if (p_pipeline[index] = NULL)
         return "-1";
     else
     {
         m_numOfFiltersCreated++ ;
         return name;   
     }
 }
}

代码使用此命令序列运行良好,但如果我将 'problematic line' 更改为其他位置:

     ....
     p_pipeline[i] = new derivedClass(twoDimArray);
     ** EDIT: array[i] = new derivedClass(twoDimArray); **
     if (checkIfNewFilterCreated(i, "name") == "-1")                                                    
        throw msg;
     p_pipeline[i]->setName("name");                <------ problematic line
     ** EDIT: array[i]->setName("name"); **                <------ problematic line
     ....

,我得到:

Access violation reading location 0x00000000

抱歉代码太长,纠结了好久...

谢谢。

您在这一行有作业:

if (p_pipeline[index] = NULL)

而不是比较

if (p_pipeline[index] == NULL)

这就是您访问地址 0x00000000

的原因