I'm just learning about C++. I'm doing practice with initialize list, so I made a class like this
class Matrix
{
public:
const int x_size;
const int y_size;
int *data;
Matrix(int _x_size, int _y_size) : x_size(_x_size), y_size(_y_size)
{
data = new int[y_size][x_size];
}
~Matrix()
{
delete[][] data;
}
};
int main(void)
{
Matrix A = Matrix(10, 10);
return 0;
}
And compiler said as: array size in operator new must be constant. So I searched and someone said, these are not 'compiler time constant'.
But it is obvious that I can't use that size as macros in here... Then. How should I get proper-sized array with Constructor?
std::vector<int>to simplify things.delete[] data;btw - thedelete[]form covers arrays of any dimension.