I have this templated function inside a class. This is implemented in a file named Mtry.cpp
class Mtry
{
public:
template <typename DerivedV, typename DerivedF, typename Scalar>
static void cotmatrix(
const Eigen::MatrixBase<DerivedV> & V,
const Eigen::MatrixBase<DerivedF> & F,
Eigen::SparseMatrix<Scalar>& L);
};
template <typename DerivedV, typename DerivedF, typename Scalar>
void Mtry::cotmatrix(
const Eigen::MatrixBase<DerivedV> & V,
const Eigen::MatrixBase<DerivedF> & F,
Eigen::SparseMatrix<Scalar>& L)
{
// Implementation...
}
I have no problem when using that code. However, if I move the declaration towards Mtry.hpp and the implementation to Mtry.cpp I get an undefined reference
Mtry.hpp:
class Mtry
{
public:
template <typename DerivedV, typename DerivedF, typename Scalar>
static void cotmatrix(
const Eigen::MatrixBase<DerivedV> & V,
const Eigen::MatrixBase<DerivedF> & F,
Eigen::SparseMatrix<Scalar>& L);
};
Mtry.cpp
template <typename DerivedV, typename DerivedF, typename Scalar>
void Mtry::cotmatrix(
const Eigen::MatrixBase<DerivedV> & V,
const Eigen::MatrixBase<DerivedF> & F,
Eigen::SparseMatrix<Scalar>& L)
{
// Implementation...
}
I saw this question where it states that the first code should work. However I couldn't find how to separate the code properly into header and source. How should it be done?