I am using a C++ library that requires that I pass it a 2D array. Their code example gives a statically sized array like this:
double data[][2] = {
{ 10, 20, },
{ 13, 16, },
{ 7, 30, },
{ 15, 34, },
{ 25, 4, },
};
But I need to pass run-time sized data. So I was attempting to do this:
// unsigned numBins is passed in to this function and set at run time
double** binData = new double*[numBins];
for(unsigned i=0; i < numBins; ++i) {
binData[i] = new double[2];
}
//Set the data with something like
// binData[7][0] = 10;
// binData[7][1] = 100;
//Later, diligently delete my data...
However, this fails in the library I am using. It ends of graphing some garbage numbers.
I understand that arrays are not pointers. And the library may be getting confused doing a "sizeof" somewhere.
If I am unable to change this library (it's 3rd party), how do I go about passing it dynamically sized data?
Thanks, Maddie.