Original Post
Hey! I have a class CNumber which has complex number functionality, it is a template class, so I can do something like this: This has not been a problem, the problem arises in my also templated CMatrix class, which encodes matrix functionality. Particularly one of the member funtions has made me confused, namely the function IsHermitian(). This function returns true if the matrix is hermitian (is equal to the transpose of it's conjugated). To check this I have to conjugate every single element in the matrix, but this is only possible if the type of the matrix data elements is CNumber!: For example, if I do something like this: CNumber has a member function which returns the conjugate of itself but double does not. But IsHermitian() need to conjugate the values of the matrix! Why am I facing this problem? I suppose I have misunderstood something about templates? Thanks in advance!
CNumber<float> fNumber; // number with single precision
CNumber<double> dblNumber; // double prec.
CNumber<int> nNumber; // contains only integers
template <class T> class CMatrix
{
private:
T* m_Matrix;
int m_dimX, m_dimY;
public:
BOOL IsHermitian();
...
};
CMatrix<double> dblMatrix; // matrix with all data elements of type double
CMatrix<CNumber<double >> numMatrix; // matrix with all data members CNumber<double>
dblMatrix.IsHermitian(); // won't work because double has ofcourse no member func. Conjugate()
numMatrix.IsHermitian(); // this is fine, CNumber has a member func. Conjugate();