Archived

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

peter86

Pointer to array problem

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