I have a problem linking to my template operator functions. They are declared and defined in the header so I don't actually know why the compiler can't find it.
// Matrix.h
#ifndef MATRIX_H
#define MATRIX_H
namespace math {
template<_DataType>
class Matrix;
template<_T>
Matrix<_T> operator*(const Matrix<_T> &lhs, const Matrix<_T> &rhs){
// function body defined here
}
template<_T>
class Matrix {
public:
friend Matrix<_T> operator*(const Matrix<_T> &, const Matrix<_T> &);
Matrix& operator*=(const Matrix& rhs){
*this = *this * rhs;
return *this;
}
};
};
#endif
// main.cpp
#include "Matrix.h"
usingnamespace math;
int main{
Matrix<double> m;
// initialize some values in m
m *= m;
}
when i build i get a error LNK2019: unresolved external symbol message saying it can't find the operator*<double> function. not sure what is going since i am defining the template in header and not elsewhere.