Re: Converting new [] to vectors
On Feb 26, 5:31 pm, Richard Howard <rhphotography....@googlemail.com>
wrote:
I am currently working on some legacy software, and I tend to replace
calls to new/delete with auto_ptrs and new[]/delete[] with vectors ...
but how do I implement the following whist maintaining RAII, is there
a std method of doing this?
float (* coords)[3] = NULL;
...
long numPoints = sourceOfPoints->size();
coords = new float[numPoints][3]; // allocate the array of arrays
sourceOfPoints->GetPointAll(coords); // set the appropriate array
values on the array of arrays
...
delete [] coords;
I thought maybe
vector<float[3]>
but it complains at me
I would be inclined to do something like this:
struct Point3D
{
float value[3];
float operator[](int i) const { return value[i]; }
float& operator[](int i) { return value[i]; }
};
vector<Point3D> coords;
coords.resize(sourceOfPoints->size());
sourceOfPoints->GetPointAll(coords);
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]