Multidimensional Arrays on the free store

Discussion in 'C++' started by Cameron, Aug 22, 2004.

  1. Cameron

    Cameron Guest

    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.
     
    Cameron, Aug 22, 2004
    #1
    1. Advertising

  2. 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.pennware.com ftp://ftp.pennware.com
     
    Richard Pennington, Aug 22, 2004
    #2
    1. Advertising

  3. "Cameron" <> wrote in message
    news:cgatul$pgr$1$...
    >
    > 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 = new char[64];
    }

    / WP
     
    William Payne, Aug 22, 2004
    #3
  4. Cameron

    Mike Wahler Guest

    Re: [FAQ] Multidimensional Arrays on the free store

    "Cameron" <> wrote in message
    news:cgatul$pgr$1$...
    >
    > 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-lite/freestore-mgmt.html#faq-16.15

    -Mike
     
    Mike Wahler, Aug 22, 2004
    #4
  5. Cameron

    Cameron Guest

    Re: [FAQ] Multidimensional Arrays on the free store

    Mike Wahler wrote:
    > "Cameron" <> wrote in message
    > news:cgatul$pgr$1$...
    >
    >>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-lite/freestore-mgmt.html#faq-16.15
    >
    > -Mike
    >
    >

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

    ~Cameron
     
    Cameron, Aug 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. d[ - - ]b

    Multidimensional arrays? anything else?

    d[ - - ]b, May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,684
    AlexS
    May 18, 2004
  2. Philipp
    Replies:
    21
    Views:
    1,186
    Philipp
    Jan 20, 2009
  3. Francesco
    Replies:
    2
    Views:
    1,169
    Francesco
    Nov 6, 2009
  4. PerlFAQ Server
    Replies:
    0
    Views:
    109
    PerlFAQ Server
    Jan 23, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    126
    PerlFAQ Server
    Apr 9, 2011
Loading...

Share This Page