views:

497

answers:

3

This problem is from a solved problem in my old question, which is from: http://stackoverflow.com/questions/394763/c-inserting-2d-array-object-into-another-2d-array-object

But also created a new problem for me. Please read the question and the solution in the link to understand my problem. The solution in the previous question was to make my Data Member Function into a pointer to pointer, to allow the pass into the other Data Member Function. But while fixing that, the first Data Member Function which is "smallerArray.extractPiece()" now only return address of the pointer to the pointer and not the content of those pointers. I need the content in order for my 2nd Data Member Function "largerArray.extractArray(result)" to work properly, as I attempt run the code and gave an Window Error, and not a Compile Error.

Does anyone know how to extract the content of the smallerArray.extractPiece() and instead of getting of the address, and is there isn't, does anyone have any other methods of creating a 2D-Array Object?

A: 

Right now, your problem seems a bit underspecified. How large of a 'piece' do you expect from the smaller array, and where in the larger array do you want to insert it?

+1  A: 
void Grid::extractArray( int** arr )
{
  for(int i = 0; i < xGrid ; ++i) {
    for (int j = 0; j < yGrid ; ++j) {
      squares[i][j] = arr[i][j];
    }
  }
}

The smaller array 'int**arr' does not have that many ellements as the Grid. xGrid and yGrid are to large to use as indices for arr[][]. You must pass the complete smaller array object into the extractArray() funtion and use the sizes from this object for the copy function.

void Grid::extractArray( const Piece & piece)
{
  for(int i = 0; i < piece.xGrid ; ++i) {
    for (int j = 0; j < piece.yGrid ; ++j) {
      squares[i][j] = arr[i][j];
    }
  }
}
marioddd
A: 

It may make things easier if you create a 2D array object or class (or struct)

class BaxMatrix { public: int m_Data[4][4]; }

with a little work you could build dynamic structures or use STL structures as desired. The data, and the reference to the data are two different animals. It's best for you to clarify each of their roles in your thinking, before proceeding forward.

Mark Essel