0

I have defined 2 functions in my class Matrix as follows (in Matrix.hpp)

static Matrix MCopy( Matrix &a );   
static Matrix MatInvert( Matrix &x )
static double MatDet( Matrix &x ); // Matdef function

In my Matrix.Cpp file, I defined these functions as follows:

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; 
}

ok this is the my MatDef function

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;
 }

but when I compile this, I get an error telling me that:

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&]’:

I can not understand what the problem is since I am new to C++ programming, so please help me in fixing this error.

Where I have used

  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!

9
  • Can you provide the code for how you're calling the method? I think you're close... Commented May 31, 2011 at 13:54
  • 1
    possible duplicate of non-static vs. static function and variable. Commented May 31, 2011 at 13:54
  • 4
    The error does not appear to happen in the code you show us (the message says it is in Matrix::MatDet. Please post that code, and indicate the line where the error is. Commented May 31, 2011 at 13:56
  • The problem seems to be inside MatDet, which is not on your code. Commented May 31, 2011 at 13:56
  • Since there was at least one typo in the error message (now fixed), I wonder if the square brackets are also typos? It is unhelpful to omit the line number and other information too. Commented May 31, 2011 at 14:00

2 Answers 2

4

If you have a class called A and it has a static function foo you would call it this way

A::foo();

Reading material

Sign up to request clarification or add additional context in comments.

Comments

0

It seems that you are trying to access a variable of the class from a static member function of that class. Static member functions cannot access regular variables of the class.

You need to check the link that @Woot4Moo suggested:

non-static vs. static function and variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.