C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Class array ? (2 dimensional)

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
eb
Guest





PostPosted: Sun Jun 11, 2006 9:10 am    Post subject: Class array ? (2 dimensional) Reply with 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.
Back to top
Alan Johnson
Guest





PostPosted: Sun Jun 11, 2006 9:10 am    Post subject: Re: Class array ? (2 dimensional) Reply with quote



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





PostPosted: Mon Jun 12, 2006 9:10 am    Post subject: Re: Class array ? (2 dimensional) Reply with quote



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 Sad )

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.