I have a template Matrix class and I used a std::vector< std::vector<T> >
to store data. I need to specialize some methods for complex matrix, for example:
template <typename T>
bool Matrix<T>::is_hermitian() const
{
if(!(*this).is_squared())
return false;
for(int r=0;r<rows_;r++)
for(int c=0;c<columns_;c++)
if(mat[r][c]!=mat[c][r])
return false;
return true;
}
For the specialized method I thought something like that:
template <typename T>
bool Matrix<std::complex<T> >::is_hermitian() const
{
if(!(*this).is_squared())
return false;
for(int r=0;r<rows_;r++)
for(int c=0;c<columns_;c++)
if(mat[r][c]!=std::conj(mat[c][r]))
return false;
return true;
}
But the compiler returns me an 'invalid use of incomplete type' error.
I instantiated at the end of the .cpp file a bunch of class that I could be using in the main program:
template class Matrix<int>;
template class Matrix<double>;
template class Matrix<float>;
template class Matrix< std::complex<float> >;
template class Matrix< std::complex<int> >;
How can I implement one method for all std::complex<T>
type?
And if you know how to replace the last two instance with a Matrix< std::complex<T> >
sort of thing I will be very thankful.
Aucun commentaire:
Enregistrer un commentaire