c++ - Runtime check failure #2 - Stack around variable was corrupted -
i'm attempting make program transpose (2 x 2) matrix using 2-dimensional array. besides runtime failure i'm having issue in inputting integer value index [0][1], value of [1][0] going index [0][1] [1][0]. value of [0][0] , [1][1] inputted cin keyword when asked during execution. didn't seem receive compilation errors should worry me either. added stdio header well, in case may somehow or anything.
#include "iostream" #include "stdio.h" #include "conio.h" using namespace std; class transpose { public: int m[1][1], te; void input(); void process(); void output(); }; void transpose::input() { cout << "matrix format:"<< endl << "[a b]" << endl << "[c d]" << endl; cout << "enter a: "; cin >> m[0][0]; cout << "enter b: "; cin >> m[0][1]; cout << "enter c: "; cin >> m[1][0]; cout << "enter d: "; cin >> m[1][1]; cout << "entered matrix:" << endl << "[" << m[0][0] << " " << m[0][1] << "]" << endl; cout << "[" << m[1][0] << " " << m[1][1]<<"]" << endl; } void transpose::process() { te = m[0][1]; m[0][1] = m[1][0]; m[1][0] = te; } void transpose::output() { cout << "transposed matrix:" << endl << "[" << m[0][0] << " " << m[0][1] << "]" << endl; cout << "[" << m[1][0] << " " << m[1][1] << "]"; } void main() { class transpose t; t.input(); t.process(); t.output(); _getch(); }
the output i'm getting during execution (within debugging mode of vs 2013) is: http://screencloud.net/v/gbqp
nb: runtime error popup occurs after press character program complete execution [i.e. after press key @ _getch() command].
i tried searching previous stack variable corruption examples couldn't find way remove error.
your matrix 1 1, using if 2 2:
m[0][1]; // valid index 0
this out of bounds access undefined behaviour. need fix that.
Comments
Post a Comment