内存访问违规VC ++

时间:2012-05-10 00:06:48

标签: access-violation memory-access

我遇到了内存访问冲突,我无法弄明白。我猜我的语法可能在某处错了。这是我的代码

load(double **pDouble)
 {
   int size;

   //pStruct is returned by a method of some object inside load
   // arr is an array of double, also member of struct pointed by pStruct.
   size = sizeof(pStruct->arr)/sizeof(double);
   *pDouble =  new double[size];
   for(int i = 0 ; i < size; i++)
   {
     *pDouble[i] = pStruct->arr[i];
       //the violation occurs for the second iteration of 
      // the loop
   }
 }

可能导致访问冲突的原因是什么?

1 个答案:

答案 0 :(得分:1)

数组索引绑定比指针解除引用更紧密。你可能意味着:

(*pDouble)[i] = pStruct->arr[i];

但可能还有其他错误。