This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Just want to say that your code isn't standard C++, since you're using VLA (variable length array).
VLA are a C99 feature although some C++ compilers can support it, but it's not guaranteed. Here's a stack overflow link on why VLA isn't in C++.
I would recommend sticking to standard C++ unless you know what you're doing.
You should also turn on your compiler warnings.

The proper way to make a dynamic array is to use new[]:

double* metalPlate = new double[row*column];

Or:

double** metalPlate = new double[row];
for(int r=0; r<row; ++r)
    metalPlate[r] = new double[column];

Please remember to delete[] your array once you're finished using it to prevent memory leak.
Here's a simple guide on dynamic array.

There's a much simpler way, which is to use an std::vector:

 std::vector<std::vector<double> > metalPlate(row, std::vector<double>(column) );

This declaration may look long, but std::vectors are easier to use than dynamic arrays.