Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Multidimensional Arrays on the free store

Reply
Thread Tools

Multidimensional Arrays on the free store

 
 
Cameron
Guest
Posts: n/a
 
      08-22-2004

Anyone know how you put multidimensional arrays on the free store?
singles work fine but I get conversion errors when I try to specify
the second, that is...

grid_cell *cells2 = new grid_cell[64];

is fine but...

grid_cell *cells2 = new grid_cell[64][64];

gives the error...

cannot convert from 'struct grid_cell (*)[64]' to 'struct grid_cell *'

I'm guessing there is a rather simple solution to this but for the life
of me it doesn't want to present its self.
 
Reply With Quote
 
 
 
 
Richard Pennington
Guest
Posts: n/a
 
      08-22-2004
Cameron wrote:

>
> Anyone know how you put multidimensional arrays on the free store?
> singles work fine but I get conversion errors when I try to specify
> the second, that is...
>
> grid_cell *cells2 = new grid_cell[64];
>
> is fine but...
>
> grid_cell *cells2 = new grid_cell[64][64];
>
> gives the error...
>
> cannot convert from 'struct grid_cell (*)[64]' to 'struct grid_cell *'
>
> I'm guessing there is a rather simple solution to this but for the life
> of me it doesn't want to present its self.


Deja Vu from today on comp.language.c.

grid_cell (*cells2)[64] = new grid_cell[64][64];

-Rich
--
Richard Pennington
Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.pennware.com ftp://ftp.pennware.com

 
Reply With Quote
 
 
 
 
William Payne
Guest
Posts: n/a
 
      08-22-2004

"Cameron" <(E-Mail Removed)> wrote in message
news:cgatul$pgr$1$(E-Mail Removed)...
>
> Anyone know how you put multidimensional arrays on the free store?
> singles work fine but I get conversion errors when I try to specify
> the second, that is...
>
> grid_cell *cells2 = new grid_cell[64];
>
> is fine but...
>
> grid_cell *cells2 = new grid_cell[64][64];
>
> gives the error...
>
> cannot convert from 'struct grid_cell (*)[64]' to 'struct grid_cell *'
>
> I'm guessing there is a rather simple solution to this but for the life of
> me it doesn't want to present its self.


Well, say you want a two-dimensional array of chars allocated dynamically. I
would declare a pointer-to-a-pointer-to-char and allocate an array of
pointers. Then I would loop through the array an allocate space for each
pointer. When you deallocate, you loop through the elements first.

char** foo;
foo = new char*[64];
for(int i = 0; i < 64; ++i)
{
foo[i] = new char[64];
}

/ WP


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      08-22-2004
"Cameron" <(E-Mail Removed)> wrote in message
news:cgatul$pgr$1$(E-Mail Removed)...
>
> Anyone know how you put multidimensional arrays on the free store?
> singles work fine but I get conversion errors when I try to specify
> the second, that is...
>
> grid_cell *cells2 = new grid_cell[64];
>
> is fine but...
>
> grid_cell *cells2 = new grid_cell[64][64];
>
> gives the error...
>
> cannot convert from 'struct grid_cell (*)[64]' to 'struct grid_cell *'
>
> I'm guessing there is a rather simple solution to this but for the life
> of me it doesn't want to present its self.


http://www.parashift.com/c++-faq-lit...html#faq-16.15

-Mike


 
Reply With Quote
 
Cameron
Guest
Posts: n/a
 
      08-22-2004
Mike Wahler wrote:
> "Cameron" <(E-Mail Removed)> wrote in message
> news:cgatul$pgr$1$(E-Mail Removed)...
>
>>Anyone know how you put multidimensional arrays on the free store?
>>singles work fine but I get conversion errors when I try to specify
>>the second, that is...
>>
>>grid_cell *cells2 = new grid_cell[64];
>>
>>is fine but...
>>
>>grid_cell *cells2 = new grid_cell[64][64];
>>
>>gives the error...
>>
>>cannot convert from 'struct grid_cell (*)[64]' to 'struct grid_cell *'
>>
>>I'm guessing there is a rather simple solution to this but for the life
>>of me it doesn't want to present its self.

>
>
> http://www.parashift.com/c++-faq-lit...html#faq-16.15
>
> -Mike
>
>

Many thanksI bookmarked that link it's just what I wanted, and thanks to
everyone else that replied

~Cameron
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 4.66 How can I store a multidimensional array in a DBM file? PerlFAQ Server Perl Misc 0 04-09-2011 10:00 PM
FAQ 4.66 How can I store a multidimensional array in a DBM file? PerlFAQ Server Perl Misc 0 01-23-2011 11:00 PM
casting pointers/arrays to multidimensional arrays Francesco C++ 2 11-06-2009 09:04 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
FREE 20 4x6 Digital Prints FREE 8x10 Print FREE Photo Website to Store and Share Photo's flashlarue Digital Photography 1 02-10-2006 11:47 PM



Advertisments