我要进行矩阵运算,就自己定义了一个类CMatrix,对加号、减号、乘号进行重载,这些运算符的重载是作为CMatrix的友元进行的。
  碰到一个问题,我写的这个CMatrix在某个工程里能够正常运行,但放到另外一个工程中却说减号的重载出错,我把减号的重载屏蔽掉,就正常了。问题是我对加号、减号的重载规则是一摸一样的,仅仅是减号的矩阵元素由加法运算变为减号运算而已,这样的出错很奇怪啊。如果加号、减号的重载都出错还好理解一些啊,呵呵。
当点击VC菜单中“Build All”出错的提示是“fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) 。Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information”这里给出一些CMatrix的代码:
//Matrix.h中的一些代码
class CMatrix{
...
...
friend CMatrix operator + (const CMatrix& a,const CMatrix& b);
friend CMatrix operator - (const CMatrix& a,const CMatrix& b);
...
...};//Matrix.cpp中的一些代码,加号的重载代码几乎一样,仅仅是循环中是加法运算而已
CMatrix operator - (const CMatrix& a,const CMatrix& b)//overload A-B
{
    int i,j;
    int aRow,aCol,bRow,bCol; aRow=a.m_Row;//m_Row,m_Col是CMatrix的成员变量,表示矩阵的行列数
aCol=a.m_Col;
bRow=b.m_Row;
bCol=b.m_Col;    if(aRow<=0 || bRow<=0 || aCol<=0 || bCol<=0 || aRow!=bRow || aCol!=bCol)
    {
        AfxMessageBox("矩阵不匹配");
        exit(1);
    }
    else if(aRow==bRow && aCol==bCol)
    {
        CMatrix c(aRow,aCol);
        for(i=0;i<aRow;++i)
        {
   for(j=0;j<aCol;++j)
   {
c(i,j)=a(i,j)-b(i,j);//这里的括号已经重载过了,是正确的
   }
}
        return c;
     }
    
}