随笔-0  评论-0  文章-1  trackbacks-0

请教大家一个问题    
// 赋值函数
Matrix& Matrix::operator=(const Matrix& M)
{
if(this != &M)
{
for (int ii = 0 ;ii < rows;ii++ )
if(pMatrix[ii])
delete[] pMatrix[ii];
if(pMatrix)
delete[] pMatrix;
rows = M.rows;
columns = M.columns;
//分配存储空间
pMatrix = new int* [rows];
for (int k = 0 ; k < rows; k++ )
pMatrix[k] = new int[columns];

for ( int i = 0 ; i < rows; i ++ )
for ( int j = 0 ; j < columns; j ++ )
pMatrix[i][j] = M.pMatrix[i][j];
}
return *this;





void  Mul(Matrix   & a,Matrix   & b);
void  Mul( Matrix   & a, Matrix   & b){
   Matrix c(a.GetRows(),b.GetColumns());

   int  temp = 0 ;  
   for ( int  ai = 0 ;ai < a.GetRows();ai ++ )
   {   
    for ( int  bj = 0 ;bj < b.GetColumns();bj ++ )
     for ( int  aj = 0 ;aj < a.GetColumns();aj ++ )
     {
      temp = temp + a.pMatrix[ai][aj] * b.pMatrix[aj][bj];
      c.pMatrix[ai][bj] = temp;
      temp = 0 ;
     }
   }
  // 输出相乘后的矩阵 c.GetColumns() ++ ) 
  {
  for ( int  i = 0 ;i < c.GetRows();i
   cout<<endl;
   for ( int  j = 0 ;j <c.GetColumns() ;j ++ )
    cout << c.pMatrix[i][j] << "    " ;
  }
  cout<<endl;
}



  Matrix Ma( 2, 1),Mb( 1, 2 );
  Mul(Ma,Mb);
运行该语句时会调用Matrix& Matrix::operator这个函数吗



posted on 2006-04-29 09:51 飞翔酷雨 阅读(48) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理