I have the following function:
template <typename DATA_T, std::size_t K, std::size_t F>
void write_raw_file(const std::string& filename, Eigen::Matrix<DATA_T, K, F>& data) {
std::fstream out_file = std::fstream(filename, std::ios::out | std::ios::binary);
for(std::size_t i = 0; i < data.rows(); i++) {
for(std::size_t j = 0; j < data.cols(); j++) {
out_file.write((char*) &data(i,j), sizeof(DATA_T));
}
}
out_file.close();
}
I'm calling it with:
std::string filename = "my_file.raw";
Eigen::Matrix<DATA_T, K, static_cast<std::size_t>(1)> my_mat;
write_raw_file(filename, my_mat);
It appears that the compiler can't match the template types as I get this error:
error: no matching function for call to ‘write_raw_file(std::string&, Eigen::Matrix<float, 128, 1, 0, 128, 1>&)’
note: candidate: ‘template<class DATA_T, long unsigned int K, long unsigned int F> void write_raw_file(const string&, Eigen::Matrix<DATA_T, K, F>&)’
void write_raw_file(const std::string& filename, Eigen::Matrix<DATA_T, K, F>& data) {
note: template argument deduction/substitution failed:
note: mismatched types ‘long unsigned int’ and ‘int’
write_raw_file(filename, my_mat);
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
I'm fairly new to C++/templates. So this is kinda confusing. I've searched for similar situations but this is a pretty basic use-case and I'm at a loss as to why it's failing.
I've called the function with a std::string& and a Eigen::Matrix<DATA_T, K, F>& type.
Aucun commentaire:
Enregistrer un commentaire