First thing, this is not C, this is C++ (you have a class in it!), secondly, since this is C++, why involve too much of a pointer stuff, when you can easily use other methods to do the same thing—why pointer-to-pointer-to-pointer? Maybe you are confusing the pointers-are-arrays statement a bit much, in your function,
void FAlocate(my_class ***Tab, int amount) {
Tab = (my_class**)malloc(sizeof(my_class*)*amount); for (int i = 0; i < amount; i++) {
Tab = (my_class*)malloc(sizeof(my_class)); }
}
You allocate the memory for pointer-to-pointer, and then keep updating that with a pointer value inside the loop. Instead what you are doing is, that you are trying to make the compiler build a program where the language constructs and type safety are not being respected. Don't you think it should be, this?
void FAlocate(my_class ***Tab, int amount) {
Tab = (my_class**)malloc(sizeof(my_class*)*amount);
for (int i = 0; i < amount; i++) {
Tab[i] = (my_class*)malloc(sizeof(my_class)); }
}
This should allocate the memory for the list items. I am ignoring the 3-dimensional array concept here, on purpose, because the code itself does not make much sense.
I will end this with this, in C++, use
new
and
delete
! There is a reason they are created in the language on top of
malloc
and
free
functions provided in C standard library.
c++ - What is the difference between new/delete and malloc/free? - Stack Overflow[
^]