未处理的异常 - 访问冲突读取位置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;
}
}
}
代码使用此命令序列运行良好,但是如果我将"有问题的行"更改为其他地方:
....
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
....
,我得到:
访问冲突读取位置0x00000000
如果代码太长,我很抱歉,我挣扎了很长时间......
谢谢。
您在此行中有分配:
if (p_pipeline[index] = NULL)
而不是比较
if (p_pipeline[index] == NULL)
这就是您访问地址0x00000000
的原因
相关文章:
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 0xC0000005:读取位置0xCDCDCDC1时发生访问冲突
- 0xC0000005:读取位置0xCDCDCDCD时发生访问冲突
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 0xC0000005:访问冲突读取位置0x0000000000000008
- C++访问冲突读取位置0xDDDDDDCD当我尝试删除已更新的数组时
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- OPENCV.3.0错误:0xc0000005:访问违规读取位置0x00000000
- 访问违规读取位置传递指针以在c中写入的DLL中起作用
- vc++ 访问冲突读取位置
- C++ - 智能指针 - 访问冲突读取位置0xDDDDDDDD
- C++访问冲突读取位置错误
- 访问违规读取位置和错误读取字符串的错误
- C 访问违规读取位置0xcccccccccccccccccccc和卡对象
- C++ 访问向量动态数组中的违规读取位置0xFFFFFFFFFFFFFFFF
- 0xC0000005:访问冲突读取位置0x0000000000000000.C++
- CUDA:访问违规读取位置
- OpenGL:glDrawArrays()引发异常(nvoglv32.dll)读取位置0x00000000时发生访问冲突