Necrogigas>Your code snippet fills an array with parts of |
If by word
fills you want to say
copies, that is not true.
Exposed by the expression -- be passed as a parameter to the cast template -- multArr[2] represents the pointer to the one-dimensional array starting at the element multArr[2][0] and containing three elements. The type of multArr[2] is (*)[3], so it is not possible to initialize reference with pointer, thus I place a static_cast to pretend that address returned by mulArr[2] is address to the correct one-dimensional array of three elements. Indeed, the object is correct, and after cast I can initialize the reference by the multArr[2] in a predictable manner.
What has happened at the end?
1 2
|
std::cout << multArr[2] << std::endl;
std::cout << &arr << std::endl;
|
the addressed you will see on the console output will be the same!
So, arr
is not copy of any part of multArr, it only referred to subarray of multArr.
It does not contain elements. Still, you may think about arr as an ordinal automatic array. That what references usually do.
For instance, if you code:
there no any changes in arr, cause` it does not exist! The element multArr[2][1] has been changed.
I want to do is make part of a multidimensional array references to another array |
English is not my native, I might misunderstand you...
I supposed, that you wanted to avoid coping of the array and desired to manipulate the part of the array elements via new reference.