[C++] Strange error: Prototype and implementation of a method do not match

Started by
2 comments, last by hkBattousai 12 years, 4 months ago
[size=2][size=2][size=2][size=2][size=2][size=2]This is the method whose definition gives compiler error:
// ...

template <class T> class Matrix
{
public:[size=2]
// ...[size=2]

template <class T>
static void SolveAxb( const Matrix<T> & _A,
Matrix<T> & x,
const Matrix<T> & _b)
throw(MatrixInvalidSize, MatrixNotSquare);

// ...
};

// ...

template <class T>
void Matrix<T>::SolveAxb( const Matrix<T> & _A,
Matrix<T> & x,
const Matrix<T> & _b)
throw(MatrixInvalidSize, MatrixNotSquare)
{
// Empty. Contents of the method are commented out.
}

// ...


Compiler error:
error C2244: 'Matrix<T>::SolveAxb' : unable to match function definition to an existing declaration[/quote]

Compiler/IDE: Microsoft Visual Studio 2010


What can be the cause of this error message?
I'm totally stuck at this point.
Any help will be appreciated.
Advertisement
Is it really your intention to have the SolveAxb function be a sub-template of the templated class Matrix, or do you just want a single instance of SolveAbx for every template-instance of the class Matrix with the same type? At the moment, the Matrix class and the SolveAxb function have two different template parameters, only they are named the same so the one on the SolveAxb function shadows the one on the Matrix class.

If the latter, drop the template on the function declaration.
Drop the "template <class T>" at the method declaration.

What you are basically doing is defining a template method inside a template class. If that is intended (which by the loook of your code isn't the case), the template parameter at the method declaration needs to have a different name than the template parameter of the class declaration.
Oh, thank you.
That was an obvious mistake, but I couldn't see it. ohmy.gif

This topic is closed to new replies.

Advertisement