程序运行报错 (msvcr100d.dll) 处有未经处理的错误: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
求助:程序运行报错 (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
头文件ZStr.h
#ifndef _ZSTR_
#define _ZSTR_
#include <iostream>
#include <boost/config/warning_disable.hpp>
class ZStr
{
public:
explicit ZStr(const char* str=NULL)
{
if(NULL == str)
{
_data = new char[1];
*_data = '\0';
}else
{
_data = new char[strlen(str)+1];
strcpy(_data,str);
}
}
explicit ZStr(const ZStr& str)
{
ZStr(str._data);
}
~ZStr()
{
delete[] _data;
_data = NULL;
}
ZStr& operator=(const ZStr& src)
{
if (_data != NULL)
{
delete[] _data;
_data = NULL;
}
_data = new char[strlen(src._data)+1];
strcpy(_data,src._data);
return *this;
}
ZStr& operator+(const ZStr& src)
{
char* _backdata = new char[strlen(_data)+1];
strcpy(_backdata,_data);
if (NULL != _data)
{
delete[] _data;
_data = NULL;
}
_data = new char[strlen(_backdata)+strlen(src._data)+1];
strcpy(_data,_backdata);
strcat(_data,src._data);
if (NULL != _backdata)
{
delete[] _backdata;
_backdata = NULL;
}
return *this;
}
char* _data;
};
#endif
------解决方案--------------------
(msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
我只从这一句话入手,msvcr100.dll,这是有关控制台的一些函数的dll,包括printf之类的,0xC0000005这个异常是访问异常,在0x00000000这个地址,说明是往空指针区域写数据了,因为零地址在r3下一般是不可读写的。
至于调试方法,看调用堆栈,然后看是哪儿往空指针写数据了,就可以迎刃而解了。
头文件ZStr.h
#ifndef _ZSTR_
#define _ZSTR_
#include <iostream>
#include <boost/config/warning_disable.hpp>
class ZStr
{
public:
explicit ZStr(const char* str=NULL)
{
if(NULL == str)
{
_data = new char[1];
*_data = '\0';
}else
{
_data = new char[strlen(str)+1];
strcpy(_data,str);
}
}
explicit ZStr(const ZStr& str)
{
ZStr(str._data);
}
~ZStr()
{
delete[] _data;
_data = NULL;
}
ZStr& operator=(const ZStr& src)
{
if (_data != NULL)
{
delete[] _data;
_data = NULL;
}
_data = new char[strlen(src._data)+1];
strcpy(_data,src._data);
return *this;
}
ZStr& operator+(const ZStr& src)
{
char* _backdata = new char[strlen(_data)+1];
strcpy(_backdata,_data);
if (NULL != _data)
{
delete[] _data;
_data = NULL;
}
_data = new char[strlen(_backdata)+strlen(src._data)+1];
strcpy(_data,_backdata);
strcat(_data,src._data);
if (NULL != _backdata)
{
delete[] _backdata;
_backdata = NULL;
}
return *this;
}
char* _data;
};
#endif
------解决方案--------------------
(msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
我只从这一句话入手,msvcr100.dll,这是有关控制台的一些函数的dll,包括printf之类的,0xC0000005这个异常是访问异常,在0x00000000这个地址,说明是往空指针区域写数据了,因为零地址在r3下一般是不可读写的。
至于调试方法,看调用堆栈,然后看是哪儿往空指针写数据了,就可以迎刃而解了。