Dynamic Memory Allocation query
Hello all,
The syntax that I used for dynamically allocating a 2D array is float (*points_) [3] = new float[npoints_][3]; This approach worked quite well, unless I had a need to make points_ as my class variable. I declared float **points_ as a private data memeber of my class in the constructor when I'am trying to allocate the 2D array, I cannot figure out what could be the syntax, as I uderstand I need to define points_ as a pointer to an array of 3 elements but (*points_)[3] = new float[npoints_][3] returns an error message. Even though dynamic allocation is fun, it sucks not to know the synatx. :D Any suggestions will be greatly appreciated, |
its better to do a 2d array linearly instead of double pointers, have a look here: http://www.linuxquestions.org/questi...383#post363383
|
correct method
kev82,
Thanks for your thoughts. I' am unable to use the first approach of new[w*h], because that would require extensive changes to my program. I figured out my mistake and fixed it and the program runs fine. Please comment on the below approach, which I' am using in my program. //in the header file float (*points_)[3]; //in the member methods where I need to allocate points_ = new float[npts_][3]; |
All times are GMT -5. The time now is 06:08 AM. |