So I am not used to hardware-close programming, pointers and ram always were done for me but because I want to learn C++, I wanted to try a 2d array, that didn't work because of unknown size, so i decided to go with a 2d list.
The problem I have now though is I have no idea how the program will behave, and before I can test it I want to know if values will be copied, overwritten etc.
#include "board.h"
#include "list"
using namespace std;
void Board::initiate_board()
{
list<list<int>> list_of_rows;
for (int rows = 0; rows++; rows < Board::rows) {
list<int> new_row;
for (int columns = 0; columns++; columns < Board::columns) {
new_row.push_back(0);
}
list_of_rows.push_back(new_row);
}
}
What this is supposed to do is create a 2d list filled with 0s. I don't know though what will happen in storage and I have no way to visualise RAM and know what is were (and if I could I'd be overwhelmed) so I was hoping someone could clear this up for me.
What I think this code does is create a list of 0s, puts it into the other list and then starts a new list, deleting the old one automatically as it will not be referenced or it will be overwritter (no clue though which one). So with rows and columns at 4 it will look like
|0|0|0|0| => ... => |0|0|0|0|
|0|0|0|0|
|0|0|0|0|
|0|0|0|0|
The 2 things i am uncertain of are A: will a new list be created? Or will the old one just be increased like:
|0|0|0|0|
|0|0|0|0|0|0|0|0|
|0|0|0|0|0|0|0|0|0|0|0|0|
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
The second question is: Will the list be copied or the reference be stored? So will it after saving the 4-long-list into the first list increase the original list and as only a reference is saved increase the list[0] also to be 8 long, so that if i changed the 2nd value in the list it would be changed in every row?
|0|0|0|0| => |0|0|0|0|0|0|0|0|
|0|0|0|0|0|0|0|0|
I know this question might be very basic for someone who knows C++ but as I come from dart and python with C# being the hardware-closest language I somewhat know, this is just confusing to me. Is there a way to know what will happen other than trying it out with printing the list of lists or just guessing?
And if I wanted to save a reference and not a copy to the list, how would I then do that?