I am creating a simple Matrix class. I am trying to add a parameter without a template name to make sure that it is used with built-in types
#include <string> #include <vector> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_scalar.hpp> template <typename T, typename = typename boost::enable_if<boost::is_scalar<T> >::type> class Matrix { public: Matrix(const size_t nrow, const size_t ncol); private: const size_t nrow_; const size_t ncol_; std::vector<std::string> rownames_; std::vector<std::string> colnames_; std::vector<T> data_; };
I would like to define a constructor outside the class definition
template <typename T,typename> inline Matrix<T>::Matrix(size_t nrow, size_t ncol) : nrow_(nrow), ncol_(ncol), rownames_(nrow_), colnames_(ncol_), data_(nrow_*ncol) {};
g ++ returns the following error
Matrix.hh:25:50: error: invalid use of incomplete type 'class Matrix<T>' inline Matrix<T>::Matrix(size_t nrow, size_t ncol)
Do you know how to solve this problem?
Thanks in advance.
c ++ matrix templates inline
Florian Plaza OΓ±ate
source share