I want to create a multi-dimensional array in runtime in as simple way as possible. so, i tried the following way...
1 2 3
int *rows;
//then i can always create an one dimensional array in the following way
rows= new (nothrow) int[a]; if (rows==0) {cout<<"Memory couldn't be allocated for matrix rows";} //( where a is a dynamic value.)
so, i tried to extend the same idea to multidimensional array ain the following way
1 2 3 4 5 6 7
int **mat;
mat = new (nothrow) int * [b]; if (mat==0){cout<<" error message";}
/*it worked fine, i mean no syntax errors, but now i want to know what kind of structure does it creates...
one dimensional vector with a pointer (likely ) or a two dimensional array(very unlikely)
i want to use it as a two dimensional array... how can that be possible... pls help me...
*/
Pls help me... and pls do let me know if my idea is valid or not.
class Matrix
{
private:
int *rows; // one dimensional array
int *cols; // one dimensional array
int **mat; // two dimensional array
int i, j; //input value for the rows and matrix of the matrix...
public:
Matrix()
{}
void setMatrix()
{
cout<<"Please input the Number of rows for the matrix:"; cin>>i;
cout<<"Please input the Number of columns for the matrix:"; cin>>j;
rows= new (nothrow) int[i]; if (rows==0) {cout<<"Memory couldn't be allocated for matrix rows";}
cols= new (nothrow) int[j]; if (cols==0) {cout<<"Memory couldn't be allocated for matrix columns";}
mat = new (nothrow) int *[j]; if (mat==0){cout<<"memory allocation error";}
getNewElements();
}
void getNewElements()
{
/* null */
}
};
int main(void )
{
Matrix a;
getch();
a.setMatrix();
getch();
return 0;
}
thank you grey wolf.
actually i posted it there... and later thought, since that was a beginners forum noone would reply me... and reposted it here... but i forgot to delete it tehre...