Reputation: 11733
i'm using Armadillo lib for linear algebra and i'm new to c++.
need to serialize some matrix in std::String (for save it in some xml) and there some ready method that take a stream.
due to the fact that i'm not used to read c++ code full of streamstring operation (i am a python programmer) i decided to make some methods that work with string and hide the stream stuffs for improve my code readability.
for make an improvment in my c++ knowledge i decide to try the use of template for make one method for all armadillo classes: mat, rowvec, colvec (they all have .load() and .save())
i decided to write those methods in a separate file utils.h, it should be usefull in future project too!
the problem is with the second method:
using namespace std;
// 1°
template<typename Matrix>
string matrix_to_string(Matrix& m) {
stringstream ss;
m.save(ss, arma::arma_ascii);
return ss.str();
}
// 2°
template<typename Matrix>
Matrix matrix_from_string(string& s) {
stringstream ss;
ss << s;
Matrix m;
m.load(ss, arma::arma_ascii);
return m;
}
the first method works perfectly, but with the second one.. if i try to use it i get the error:
no matching function for call to ‘matrix_from_string(std::string&)’
i'm calling it in this way:
mat prior;
string s = XML.getValue("prior", ""); // my XML lib, it works fine
prior = matrix_from_string( s );
what's happening?
Upvotes: 2
Views: 263
Reputation: 8614
Change the line
prior = matrix_from_string( s );
to
prior = matrix_from_string<mat>(s);
Upvotes: 3