 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
eb Guest
|
Posted: Sun Jun 11, 2006 9:10 am Post subject: Class array ? (2 dimensional) |
|
|
Hello,
This *should* be simple, but I'm not knowledgeable enough so as to get it by
myself.
Suppose I want a double array of a custom class (say MyTile, to tile a
square).
How would I declare it in MyTiledSquare.h ?
I did not succeed with "MyTile **myTiles ;"
The trick is : I want the tiling size (the number of tiles per row / lines)
to depend on a variable. Therefore, I don't want to fix the array size
there.
Then, how would I initialise it in MyTiledSquare.cpp ?
The array size is dependent on a variable which is in the MyTiledSquare
class.
In the end, I would like to access an element with MyTile[i][j]
Thanks for any clues. |
|
| Back to top |
|
 |
Alan Johnson Guest
|
Posted: Sun Jun 11, 2006 9:10 am Post subject: Re: Class array ? (2 dimensional) |
|
|
eb wrote:
| Quote: | Hello,
This *should* be simple, but I'm not knowledgeable enough so as to get it by
myself.
Suppose I want a double array of a custom class (say MyTile, to tile a
square).
How would I declare it in MyTiledSquare.h ?
I did not succeed with "MyTile **myTiles ;"
The trick is : I want the tiling size (the number of tiles per row / lines)
to depend on a variable. Therefore, I don't want to fix the array size
there.
Then, how would I initialise it in MyTiledSquare.cpp ?
The array size is dependent on a variable which is in the MyTiledSquare
class.
In the end, I would like to access an element with MyTile[i][j]
Thanks for any clues.
|
You'll save yourself a lot of headache if you use std::vector. Example:
unsigned rows = 25, cols = 80 ;
std::vector< std::vector<T> > v(rows, std::vector<T>(cols)) ;
--
Alan Johnson |
|
| Back to top |
|
 |
eb Guest
|
Posted: Mon Jun 12, 2006 9:10 am Post subject: Re: Class array ? (2 dimensional) |
|
|
Alan Johnson wrote:
| Quote: |
Or, if you want to do it all together:
size_t rows = 25, cols = 80 ;
std::vector< std::vector<QCanvasLine> > lines(rows,
std::vector<QCanvasLine>(cols, QCanvasLine(canvas))) ;
|
Close ... What dod the trick was :
std::vector< std::vector<QCanvasLine> > HGatter (board_size,
std::vector<QCanvasLine>(board_size, QCanvasLine::QCanvasLine(canvas))) ;
Now I can compile.
Unfortunately, the code does not work yet
(I have then the initialisation of each HGatter line, but they would not
show )
int i,j;
for (i=0; i<board_size; i++)
for (j=0; j<board_size; j++)
{
HGatter[i][j].setPoints(offsetX + square_size * i, offsetY,
offsetX + square_size * i, offsetY + board_pixel_size);
HGatter[i][j].show();
}
Thanks anyway. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|