变量周围的堆栈已损坏

时间:2012-11-25 14:43:58

标签: c++ stack stack-corruption

我知道这个主题有很多问题,但它们似乎都与代码有关。

我有这个功能 -

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
   }

它在return语句中给出了一个错误,说“运行时检查失败#2 - 变量'结果'周围的堆栈已损坏。”

我看不出那个功能有什么问题。 Matrix3x3的数组只是 -

float array[3][3];

并且Point2的数组是

float array [2];

Matrix3x3和Point2类都有此代码 -

/** 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];}

这段代码是给我的,我以前做过一些功课,用点,母体和矢量做算术。我的代码通过了所有测试,所以我假设我的Point2 ITCS4120 :: operator *(const Matrix3x3&amp; m,const Point2&amp; p)代码是正确的。但也许我需要以不同的方式使用[]运算符?

1 个答案:

答案 0 :(得分:6)

看来你的观点包含两个float,但你写的是三个。

相关问题