Results 1 to 18 of 18

Thread: Arrays of structs with unspecified size

Hybrid View

  1. #1
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Arrays of structs with unspecified size

    Sorry, my mistake, forgot the *.
    sMap* sMapPtr=new sMap[runtime number does not have to be constant];

    I don't know VB though so I can't help you converting snippet.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    The Netherlands
    Posts
    386

    Re: Arrays of structs with unspecified size

    Code:
    	sMAP* sMapPtr = new sMAP[mapwidth][mapheight];
    my compiler still whines about how the array bound is not constant


    and I get a different error too:

    error C2440: 'initializing' : cannot convert from 'struct sMAP (*)[1]' to 'struct sMAP *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

  3. #3
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Arrays of structs with unspecified size

    Don't try to make a 2 dimentional array. Treat it like a bitmap and do manual address translation like CB said.
    sMAP* sMapPtr = new sMAP[mapwidth*mapheight];

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    The Netherlands
    Posts
    386

    Re: Arrays of structs with unspecified size

    Hey, thanks!
    When CornedBee spoke of manual address translation, I didn't think that he meant that, so thanks to the both of you!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    The Netherlands
    Posts
    386

    Re: Arrays of structs with unspecified size

    I find this quite strange... This method works very well when the compiler is set to C++, but when it is set to just C, it doesn't like what it sees... Is that because this is only a C++ method of doing that?

  6. #6
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Arrays of structs with unspecified size

    new and delete are c++,
    malloc and free are c and c++.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    The Netherlands
    Posts
    386

    Re: Arrays of structs with unspecified size

    I'm also having trouble with something else.. the scope of the pointer. Say I load the map, but in the same function I declare that pointer, as I get the mapwidth and mapheight variables from the file... I can't use that same pointer in a different function, like the Render function...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width