i'm trying to make a matrix class and i want to use 2 dimensional arrays for them. i know you can use vectors(easy way) but is there a way to re-size the array?? with out accidentally over writing something else?
i know it has something to do with new and delete but i'm not familiar with them
I may be wrong in saying this - but is this possible at all?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//Include Class Header and this files header here...
MatrixClass* CreateMatrix(int &arraySizeOne, int &arraySizeTwo)
{
std::cin >> arraySizeOne, arraySizeTwo;
MatrixClass* myCreatedMatrix = new MatrixClass[arraySizeOne][arraySizeTwo];
return myCreatedMatrix;
}
//New File for delete function
void DeleteMatrix(MatrixClass* myCreatedmatrix, int arraySizeOne, int arraySizeTwo)
{
delete[][] myCreatedMatrix;
}
Probably not correct syntax - but it's kind of possible like this isn't it?
For the top bit using the class like method - in another file or somewhere else on the page. You would have another pointer thats pointing to the real class and make it edit that?
Hmm, now i'm a little confused - mat = new float[r][c]; is a 2d array which i gather is what you want. But your other one is a single array its just 1 long line. As lets say your r = 10 and c = 10 - then all thats doing is making a long single array with an x-axis value of 100. Doing it the way you have at the top using "new float[r][c]" would be making a y-axis value of 10 and an x-axis value of 10 as well.
And as for mat[r][c] = num; what exactly do you want to happen here?