I have called a template in my C++ program:
const matrix::CMatrix<double> M1(3,3,{{5.0,0.0,2.0},{1.0,1.0,3.0},{6.0,7.0,7.0}});
i got such linker error:
tests.h:15: undefined reference to `matrix::CMatrix<double>::CMatrix(int, int, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >)'
after massive search, finally i realized it is because i have separated my h and cpp files and template
does not tolerate it. In C it is suggested to separate c and h files and using Makefile. But according to such problems in c++ is it still suggested to separate cpp and h files? It is not clean way to implement some templates in h files and some other functions in cpp file. what should i do?
edit:
matrix.h
template<typename T>
class CMatrix
{
.....
matrix.cpp
implementation of CMatrix
main.cpp
defining M1