It seems your point contains two float
s but you are writing to three.
Stack around variable is corrupted
-
02-12-2021 - |
Question
I know this topic has a lot of questions, but they all seem specific to the code.
I have this function -
Point2 ITCS4120::operator* (const Matrix3x3& m, const Point2& p) {
Point2 result;
for(int i=0;i<3;i++) {
result[i] = (m[i][0]*p[0]) + (m[i][1]*p[1]) + (m[i][2]);
}
return result; //error here
}
It gives me an error on the return statement saying "Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted."
I cannot see anything wrong with that function. The Matrix3x3's array is just -
float array[3][3];
and the Point2's array is
float array [2];
Both the Matrix3x3 and Point2 classes have this code -
/** Write access for element in row [i] */
inline Scalar* operator[](int i) {return array[i];}
/** Read access for element in row [i] */
inline const Scalar* operator[](int i)const {return array[i];}
This code was given to me and I had some previous homework to do arithmetic with points, matricis, and vectors. My code passed all the tests so I assumed my Point2 ITCS4120::operator* (const Matrix3x3& m, const Point2& p) code was correct. But maybe I need to use the [] operators differently?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow