Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll try to take a different approach and give a comprehensive answer, perhaps it will be more clarifying. <strong>The function will take any variable that fits the exact type of the parameter it was declared with</strong>. A basic array in C++ is simply a constant pointer (Points to the beginning, holds the space size for the rest). Storing an array of arrays by memory allocation using pointers is not exactly the same as a 2D array generated by C++ (The assembly code generated for <code>datatype arrays[const][const]</code> and for <code>**arrays = new datatype[const]</code>is different). This is important to know because your can draw the <strong>distinction between a pointer to a pointer and a 2D C++ generated array</strong>. </p> <p>To keep things simple, <strong>treat your parameter exactly as it is: a pointer to a pointer</strong>. If that is what you are passing to the function, which is your case, then you are passing the right variable to the right parameter. <strong>The way you handle that parameter within the function will be what determines if you are treating it as a 2D array or not</strong>.</p> <p>I'm answering this way because there seems to be some doubt on why a pointer to a pointer is treated as a 2D array. If that is the case, you are right to doubt. The <strong>2D array is just an interpretation</strong> of what the variable is holding, but the <strong>variable is still a pointer to a pointer</strong> and you give it the same treatment as with other pointer variables (Memory allocation and deallocation, passing as parameter, handling, etc...).</p> <p>As for replacing it with structs (classes) and whatnot: I believe you are doing things that way in order to <strong>better comprehend memory allocation and pointing</strong> by creating dynamic multidimensional arrays, using C++ simply as the mean. If that is the case, then I believe my answer will fit your needs well. Otherwise, there are alternatives which are better abstracted and that will automatically handle memory allocation (For C++, search for STL containers). By doing it your way, you increase your understanding of what goes on "behind the scenes", if you will. It is knowledge of <strong>greater importance in computational science</strong> than in modern or future programmatic usage. </p> <p>Hopefully the answer was such that you will be able to handle similar situations by understanding what is happening, which is generally the true cause for incorrect syntax in these cases. English is not my native language; I apologize in advance for possible semantic misuses.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload