Answer the question
In order to leave comments, you need to log in
How to fix template error LNK2019?
The error itself:
1>main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl Furdarius::MatrixHelpers::inputFromFile<int>(class Furdarius::Matrix<int> &,class std::basic_fstream<char,struct std::char_traits<char> > &)" ([email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@@Z) referenced in function "class Furdarius::Matrix<int> __cdecl initMatrixFromFile(class std::basic_fstream<char,struct std::char_traits<char> > &)" ([email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@@[email protected]@@Z)
// MatrixHelpers.h
class MatrixHelpers
{
public:
template<typename _U>
static void inputFromFile(Matrix<_U> &matrix, std::fstream &file);
// MatrixHelpers.cpp
template<typename _U>
void MatrixHelpers::inputFromFile(Matrix<_U> &matrix, std::fstream &file)
{
for (int i = 0; i < matrix.getSize().row; ++i)
for (int j = 0; j < matrix.getSize().col; ++j)
file >> matrix[i][j];
};
Matrix<int> M(size);
MatrixHelpers::inputFromFile<int>(M, file);
Answer the question
In order to leave comments, you need to log in
Template functions cannot be described in separate cpp files. Write the body of the method directly in the h file.
Yes, just in case. Is there a ";" after the class{} closing brace?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question