Memory access violation VC++
-
07-06-2021 - |
문제
I'm getting a memory access violation which i am not able to figure out. I am guessing my syntax might be wrong somewhere. Here is my code
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
}
}
What could be causing the access violation?
해결책
Array indexing binds more tightly than pointer dereferencing. You probably meant:
(*pDouble)[i] = pStruct->arr[i];
There may be other errors though.
제휴하지 않습니다 StackOverflow