Recimo, hoću da formiram klasu koja ce obrađivati matrice koje se naaze u main-u. Imam matricu u mainu i treba da je prosledim klasi. Kod mene, main (javlja mi se greska kod naredbe mat=mat1;) izgleda ovako:
Code:
int main(){
double **mat;
double mat1[2][2] = {1, 2, 3, 4};
int t=2, g=2;
mat=mat1;
MyMatrix m(t, g, mat);
m.print();
_getch();
}
int main(){
double **mat;
double mat1[2][2] = {1, 2, 3, 4};
int t=2, g=2;
mat=mat1;
MyMatrix m(t, g, mat);
m.print();
_getch();
}
Klasa MyMatrix koja treba da učita matricu mat1 izgleda ovako:
Code:
class MyMatrix{
private:
int columns;
int rows;
double *values;
public:
MyMatrix::MyMatrix(int col, int row,double**& val){
columns=col;
rows=row;
values=new double[columns*rows];
for(int i=0;i<rows*columns;i++){
values[i]=*val[i];
}
}
void MyMatrix::print(){
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
cout<<values[i*columns+j]<<"\t";
}
cout<<"\n";
}
}
};
class MyMatrix{
private:
int columns;
int rows;
double *values;
public:
MyMatrix::MyMatrix(int col, int row,double**& val){
columns=col;
rows=row;
values=new double[columns*rows];
for(int i=0;i<rows*columns;i++){
values[i]=*val[i];
}
}
void MyMatrix::print(){
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
cout<<values[i*columns+j]<<"\t";
}
cout<<"\n";
}
}
};
Unapred vam se zahvaljujem na uloženom trudu, ja vise ideja nemam sve sam probao :)
[Ovu poruku je menjao mr10x505 dana 14.12.2011. u 11:01 GMT+1]