Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

peter86

Pointer to array problem

This topic is 5468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to create a pointer to a 2D-array, but it dosen''t even compile. Here''s what it looks like: FLOAT* pMap = new FLOAT[i]; And this is the error I''m getting: error C2440: ''='' : cannot convert from ''float (*)[1]'' to ''float *'' Why dosen''t it work and how should I create a 2D-array with an undefiened number of elements?

Share this post


Link to post
Share on other sites
Advertisement
That should work (unless I am mistaken), though I dont know why you are using capitals for FLOAT (float).

Note: That is a one-dimensional array.

A static 2D array looks like:
float name[x][y];

or for the pointer version there are other methods:

float ** name;
and then you have to initialise it with a for loop.



[edited by - stevenmarky on October 5, 2003 8:07:24 AM]

Share this post


Link to post
Share on other sites
std::vector< std::vector< float > >

or

float Array[ width * height ];
float ReadArray(i,j) { return Array[ i + j*width ]; }
void WriteArray(i,j, element) { Array[i+j*width] = element; }

EDITs : duh, < > tags

[edited by - ToohrVyk on October 5, 2003 8:31:16 AM]

[edited by - ToohrVyk on October 5, 2003 8:31:47 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!