c++ - function has effects on the other functions that run before it did -
{ int x = hfilter * threebythree(i,j,getdata(),getnumrows(),getnumcols()); int y = vfilter * threebythree(i,j,getdata(),getnumrows(),getnumcols()); int value = floor(sqrt(x*x+y*y)); //evil setvalue function setvalue(i,j,value); } image image::threebythree(int globali,int globalj, int** matrix,int row,int col) { image neighbor; neighbor.setnumrows(3); neighbor.setnumcols(3); neighbor.allocatemem(); for(int i=0; i<3; ++i) { for(int j=0; j<3; ++j) { if((i+globali-1 >=0) && (j+globalj-1 >=0) && (i+globali-1 < row) && (j+globalj-1 < col)) { //cout<< matrix[i+globali-1][j+globalj-1] << " , "; neighbor.setvalue(i,j,matrix[i+globali-1][j+globalj-1]); } else { neighbor.setvalue(i,j,0); } } } for(int i=0; i<3; ++i) { for(int j=0; j<3; ++j) { cout << neighbor.getvalue(i,j)<< ","; } cout << endl; } return neighbor; } void matrix::setvalue(int i, int j, int value) { data[i][j] = value; }
what i'm doing here threebythree()
generates 3x3 matrix when traversing through big matrix 100x100.
everything works fine if comment out the:
setvalue(i,j,value);
threebythree()
prints out nice 3x3 matrix like:
47,50,0, 50,55,0, 0,0,0,
but with setvalue(i,j,value)
, runs after threebythree()
, 3x3 matrix changed to:
35384,-2147483648,0, 42428,55,0, 0,0,0,
how function have impact on functions executed before did?
Comments
Post a Comment