我在类Matrix
中定义了两个函数,如下所示(在Matrix.hpp中)
static Matrix MCopy( Matrix &a );
static Matrix MatInvert( Matrix &x )
static double MatDet( Matrix &x ); // Matdef function
在我的Matrix.Cpp文件中,我定义了以下函数:
Matrix Matrix::MatCopy( Matrix &a )
{
Matrix P( a.getRow() , a.getCol() , Empty );
int j=0;
while( j != P.getRow() ){
int i=0;
while( i != P.getCol() ){
P(j,i)=a(j,i);
++i;
}
++j;
}
return P;
}
Matrix Matrix::MatInvert( Matrix &x )
{
Matrix aa = Matrix::MatCopy(x); // i got error message here
int n = aa.getCol();
Matrix ab(n,1,Empty);
Matrix ac(n,n,Empty);
Matrix ad(n,1,Empty);
if(MatLu(aa,ad)==-1){
assert( "singular Matrix" );
exit(1);
}
int i=0;
while( i != n ){
ab.fill(Zero);
ab (i,0)=1.0;
MatRuecksub(aa, ab,ac,ad,i);
++i;
}
return ac;
}
好的,这是我的MatDef函数
double Matrix::MatDet( Matrix &x )
{
double result;
double vorz[2] = {1.0, -1.0};
int n = x.getRow();
Matrix a = Matrix::MatCopy(x);
Matrix p( n, 1, Empty);
int i = MatLu(a, p);
if(i==-1){
result = 0.0;
}
else {
result = 1.0;
int j=0;
while(j != n){
result *= a( static_cast<int>(p(j,0)) ,j);
++j;
}
result *= vorz[i%2];
}
return result;
}
但当我编译这个时,我会收到一个错误,告诉我:
line 306:no matching function for call to ‘Matrix::Matrix[Matrix]’:
note: candidates are: Matrix::Matrix[Matrix&]
note:in static member function ‘static double Matrix ::MatDet[Matrix&]’:
我不明白问题出在哪里,因为我是C++编程的新手,所以请帮助我修复这个错误。
我使用过的地方
Matrix aa = Matrix::MatCopy(x);
It shows same error message like line 306 but with different notes so I think MatDef
is not a problem.
Please give your comments to solve this. Thanks!