I am writing some function templates using armadillo linear algebra library, but it encounters some errors. I am still learning C++ and its aspects, so will be very much thankful for any possible solutions. Most of my functions are like the following,
template<typename T1>
void some_function(const Mat<T1> & p)
{
unsigned int n = p.n_rows;
// do some stuffs...
// ....
}
My main function contains:
Mat<double> A = ones<Mat<double>>(4,4);
int a(2);
some_function(A); // runs perfectly
some_function(a*A); // compilation error as follows
test_function.hpp:35:8: note: template argument deduction/substitution failed:
test.cpp:22:17: note: ‘arma::enable_if2<true, const arma::eOp<arma::Mat<double>, arma::eop_scalar_times> >::result {aka const arma::eOp<arma::Mat<double>, arma::eop_scalar_times>}’ is not derived from ‘const arma::Mat<eT>’
some_function(a*A);
If I change the function as follows:
template<typename T1>
void some_function(const T1 & p)
{
unsigned int n = p.n_rows;
// do some stuffs...
// ....
}
Then it gives the compilation error as follows:
test_function.hpp: In instantiation of ‘bool some_function(const T1&) [with T1 = arma::eOp<arma::Mat<double>, arma::eop_scalar_times>]’:
test.cpp:22:17: required from here
test_function.hpp:37:26: error: ‘const class arma::eOp<arma::Mat<double>, arma::eop_scalar_times>’ has no member named ‘n_rows’
unsigned int n = p.n_rows;
But the non-template functions work perfectly, like
void some_function(const Mat<double> & p)
{
unsigned int n = p.n_rows();
// do some stuffs...
// ....
}
Any solutions??