need help finding why SIGABRT occured
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <fstream>
using namespace std;
class matrix{
char **b=NULL;
int n;
public:
matrix(int sz):n{sz}{
b = new char*[n];
for(int i=0;i<n;++i) b[i] = new char[n];
}
void Set(int x,int y,char c){
b[x][y] = c;
}
char Get(int x,int y){
return b[x][y];
}
void Print(){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
cout<<b[i][j];
}
cout<<endl;
}
}
int Size(){ return n; }
bool operator==(matrix y){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
if(b[i][j] != y.Get(i,j)) return false;
}
}
return true;
}
~matrix(){
for(int i=0;i<n;++i) delete[] b[i];
}
};
matrix Rotate(matrix m){
int S = m.Size();
matrix x(S);
int i,j;
for(i=0;i<S;++i){
for(j=0;j<S;++j){
x.Set(j,(S-1-i),m.Get(i,j));
}
}
return x;
}
|
In the above code when comparing two matrices after recursive passing through Rotate function like this
Rotate(Rotate(Rotate(matA)))
causes a SIGABRT error.
If there are two Recursive calls like
Rotate(Rotate(matA))
there are no errors.
i couldn't find where the error occurs. Can someone tell why more Recursive call causes this error
Last edited on
You have not defined a copy constructor.
Topic archived. No new replies allowed.