动态定义数组有关问题
动态定义数组问题
void testByte(byte a[],unsigned length)
{
byte *b=new byte[length];
b[0]=10;
b[1]=20;
b[2]=32;
b[3]=21;
b[4]=71;
b[5]=69;
::memcpy(b,a,length);//将a数组 拷贝 至b数组
}
为什么这样动态申请数组 不可以呢?
把申明的语句换成以下三句:
byte b[6]; //这个可以 常量
vector<byte> b(length);//这个不可以 include <vector> using std
byte * b = (byte *)malloc(length*sizeof(byte));//这个也不可以
------解决方案--------------------
早上在单位不能私信,不能上QQ
byte * b = (byte *)malloc(length*sizeof(byte))
昨天在家测试了下又可以了。
建议
if(b == NULL) //申请失败
{
int err;
err = GetLastError();
CString cstrErr;
cstrErr.Format("%d",err);
AfxMessageBox(cstrErr);
}
把错误给答应出来,然后去Tools里面有个Error lookup把错误编号输出,就能查看原因了
void testByte(byte a[],unsigned length)
{
byte *b=new byte[length];
b[0]=10;
b[1]=20;
b[2]=32;
b[3]=21;
b[4]=71;
b[5]=69;
::memcpy(b,a,length);//将a数组 拷贝 至b数组
}
为什么这样动态申请数组 不可以呢?
把申明的语句换成以下三句:
byte b[6]; //这个可以 常量
vector<byte> b(length);//这个不可以 include <vector> using std
byte * b = (byte *)malloc(length*sizeof(byte));//这个也不可以
------解决方案--------------------
早上在单位不能私信,不能上QQ
byte * b = (byte *)malloc(length*sizeof(byte))
昨天在家测试了下又可以了。
建议
if(b == NULL) //申请失败
{
int err;
err = GetLastError();
CString cstrErr;
cstrErr.Format("%d",err);
AfxMessageBox(cstrErr);
}
把错误给答应出来,然后去Tools里面有个Error lookup把错误编号输出,就能查看原因了