This indicates that these variables are defined in another translation unit (another .cpp file.) Normally such extern declarations would be in a header file and not thrown willy-nilly into a .cpp file.
In C++ there would be no need for these const ints to be declared extern. But, this is what your instructor gave you to work with, so I guess you deal with the cuckoo professor. Seeing as they are declared extern, the proper place to define them would probably be in the same translation unit as ptr4D.
externfloat ***ptr4D[] is an array of pointers to pointers to pointers to float.
float p[DIM0][DIM1][DIM2][DIM3] = {0}; is essentially a 1-D array of floats that the compiler allows you to treat as if it was multi-dimensional. Not surprisingly, the definition (which shouldn't be in the header, by the way) doesn't match the declaration - an array of type float is not an array of type pointer to pointer to pointer to float.
I would expect ptr4D to be defined in some translation unit (.cpp file) other than the one main is in as: float *** ptr4D[DIM0] ; and presumably each element would be initialized to point to a dynamically allocated array of pointers (whose elements would be initialized to point to dynamically allocated arrays of pointers...) by some function which resides in the same translation unit. (Although, since you apparently can't modify main, that assumption would appear to be wrong.)
On the main.cpp whic is the start of the topic there are two extern declarations one for the dimensions and one for the array of pointer to pointer to pointer of type float. This is the professors program which we are not to modify.
The header file is something I did. float p[DIM0][DIM1][DIM2][DIM3] = {0}; is a variable definition so I can set aside a space in memory so all I need to do is equate the pointer declaration float ***ptr4d[] to the pointer p. This is when I have the problem.
You may say the professor is cuckoo but he gives us this exercise for a reason, he will almost tie your hand but there is always a solution, he just does not want it to be a piece of cake.
float p[DIM0][DIM1][DIM2][DIM3] = {0}; is a variable definition so I can set aside a space in memory so all I need to do is equate the pointer declaration float ***ptr4d[] to the pointer p. This is when I have the problem.
Variable definitions don't belong in header files, and this one isn't up to the problem. You need space for pointers-to-pointers-to-float, pointers-to-float, and the floats they point to, and you need to tie them all together.
You need space for pointers-to-pointers-to-float, pointers-to-float, and the floats they point to, and you need to tie them all together.
@cire is correct, in both his statements: The one above and cuckoo. It is tedious to create all of the arrays but it will work. I did it, the program compiled and it printed out the "Success!".
1 2 3 4 5 6 7
// Now define p00, p01,p02 and p10,p11,p12
// p00, p01, etc... should have dimension DIM2
// and keep going until you get to an array of floats
// i.e. p000[], p001[], etc... would be just floats
float **p0[] = {p00,p01,p02};
float **p1[] = {p10,p11,p12};
float ***ptr4D[] = {p0,p1};
I will only agree with cire's first statement, because I tried it.
it took 33 definitions/declarations to get ***ptr4D[]. Then I send it to the professor and he said, That is what I want you to learn what not to do. Next meeting I will show you how to do it correctly.
The professor works for Space and Naval Warfare Systems Command (SPAWAR) a high tech command of the US Navy and designing embedded system and programming top security projects. His style of teaching may be weird but it works.
I would compare his assignment to a request to drive from San Diego to Los Angeles. He would require his students to show him how to drive from San Diego to Los Angeles, but he would tie your hand. He will not let you use Interstate 5, not use Insterstate 15, not use Interstate 10, 405, not to use State highway 60, 91, 78, 52 and just use the side road and you only have 10 gallons of gas.
Isn't that a more challenging assignment, he ties your hand, leaves you with almost no option and finds out if you could do it. With this problem you learn how to think, and check different approach and pick the best.
With another professor who ask for solutions without any restriction their students will always say use Interstate 5 and the solution is over. That is no fun at all.