У меня это работает обычными методами. Но с методами, которые сами по себе являются шаблонами, я сталкиваюсь с некоторыми проблемами.
Используя следующую структуру:
Код: Выделить всё
#ifndef MATRIX_HPP
#define MATRIX_HPP
#include
#include
template
class Matrix
{
static_assert(std::is_arithmetic::value,
"Matrix can only be declared with a type where std::is_arithmetic is true.");
public:
Matrix();
template
Matrix slice() const;
private:
std::array data{};
};
#include "Matrix.ipp"
#endif
Код: Выделить всё
#include "Matrix.hpp"
template
Matrix::Matrix()
{}
template
Matrix Matrix::slice() const
{
auto mat = Matrix();
for (std::size_t i = y; i < m; i++)
{
for (std::size_t j = x; j < n; j++)
{
mat[i - y][j - x] = (*this)[i][j];
}
}
return mat;
}
Код: Выделить всё
#include "Matrix.hpp"
int main() {
auto m = Matrix();
auto sliced = m.template slice();
return 0;
}
Код: Выделить всё
../Matrix.ipp:14:17: error: prototype for ‘Matrix Matrix::slice() const’ does not match any in class ‘Matrix’
Matrix Matrix::slice() const
^~~~~~~~~~~~~~~
In file included from ../main.cpp:0:0:
../Matrix.hpp:20:18: error: candidate is: template template Matrix Matrix::slice() const
Matrix slice() const;
Надеюсь, кто-нибудь сможет мне помочь. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/476 ... -ipp-files