[英]Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x0) issue is generated
I'm using apple LLVM compiler for C++ development in Xcode. 我正在使用Apple LLVM编译器在Xcode中进行C ++开发。 I initialise the
char pickbuf
variable and allocate the required memory I want to assign value 1 to second code of line there. 我初始化了
char pickbuf
变量,并分配了所需的内存,我想将值1分配给那里的第二行代码。 But I'm getting a null pointer error: please help me. 但是我收到了空指针错误:请帮助我。
2DCDP4.h 2DCDP4.h
class CDP : public Const2DCDP{
struct PICK
{
short x; // Transverse connector
short y; // Vertical direction consolidated
unsigned char x0; // Transverse reduction limit
unsigned char y0; // Longitudinal reduction limit
} ;
public:
char* pickbuf =new char[1]; // Overlapping buffer allocate some
PICK* pickup =new PICK [1]; // Backtrace buffer
}
void getProjection(void);
};
2DCDP4.cpp 2DCDP4.cpp
#include "2DCDP4.h"
void CDP::getProjection(void){
char *before=pickbuf;
if( before[(j-1)*di + (i-1)] == 1) //**Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x0)**
{
//code
}
}
You haven't allocated any memory to pickbuf
, but try to access the memory at pickbuf
on the 2nd line. 您尚未为
pickbuf
分配任何内存,但尝试在第二行的pickbuf
上访问该内存。 To fix this, allocate some memory to pickbuf
before the 2nd line: 要解决此问题,
pickbuf
在第二行之前为pickbuf
分配一些内存:
char pickbuf[n];
or 要么
char* pickbuf = new char[n];
Where n
is a size large enough for you needs. 其中
n
是足以满足您需要的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.