C ++ 11 iterate on a shredded matrix?
source link: https://www.codesd.com/item/c-11-iterate-on-a-shredded-matrix.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C ++ 11 iterate on a shredded matrix?
I'm trying to initialise a jagged array. Why doesn't this work:
int *arr[10];
for (int *row : arr)
row = new int[10];
it runs but then arr is unreadable.
How can I use this form of "for" properly in this situation?
Otherwise how can I just initialise a jagged array of X rows, each row is Y elements and set all to zero?
int* arr[10];
for (int*& row : arr)
row = new int[10];
Since you are changing the value in the array inside of the loop you need to iterate over references instead of values (which are only copies of what was in the array). This is very similar to function call semantics.
Related Articles
Complete the three-dimensional array (shredded matrix) with point data
A faster way to iterate through a shredded network?
Combine two dual matched matrices in a shredded matrix in C #
How can I iterate on a JSON matrix in a jsRender model?
iterate through the matrix R
1D digital rounding condensed to 2D Hamming distance matrix
basic operations with boost c ++ ublas matrix and vector types
Practice on matrix - Ocaml
OpenCV Matte class: access to elements of a multichannel matrix
Find the index of the maximum element in the c ++ matrix?
the operands invalid to the binary expression during the overload of an operator
Java 8 forEach on multiple IntStream streams
Choose an appropriate data structure
How to get the value of each EditText of a GridView adapter?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK