There is a two-dimensional array of structures, I am passing an array pointer to a function:
result.capabilities = (Capabilities **)malloc(sizeof(Capabilities *)*6);
for(int i=0;i<6;i++){
result.capabilities[i] = (Capabilities *)malloc(sizeof(Capabilities)*8);
}
init_capabilities(&result.capabilities);
Function call cause an error:
Unhandled exception at 0x003c10f9 in solution.exe: 0xC0000005: Access violation writing location 0xfdfdfdfd.
Here is my function:
void init_capabilities(Capabilities ***capabilities) {
for(int i=0;i<6;i++){
for(int j=0;j<8;j++){
printf("%d %d\n",i,j);
capabilities[i][j]->room_capabilities = new RoomCapability[rooms_count];
}
}
}
I thought that the dimension of the array capabilities - 6x8. It turned out that 1x6.
An hour headache because of this. Show you how to change the type of argument or how to refer to elements of my array, so that everything fell into place?
newinstead ofmalloc()which C++ provides (which gives you much cleaner, straightforward syntax and is safer thanmalloc()IIRC).mallocin C++. Use references in C++ whenever possible and feasable.