I'm working on a little program where i create a 2d array. The function itself works fine, but i get a problem when i want to implement the function in its own file. This is how it looks like:
mat.cpp:
#include <iostream>
#include <iomanip>
#include "matdyn.hpp";
int main(){
int row, column;
cin >> row;
cin >> column;
int** M1;
double** M2;
reserve(M1, row, column);
reserve(M2, row, column);
return 0;
}
matdyn.hpp
#ifndef dyn
#define dyn
template <typename T, typename S>
void reserve(S **, T, T);
#endif
matdyn.cpp:
#include "matrix_dyn.hpp"
template <typename S, typename T>
void reserve(S **&x, T row, T column){
x = new S*[row];
for(int i = 0; i < row; ++i) {
x[i] = new S[column];
}
}
template void reserve<int, int, int>(int, int, int);
template void reserve<double, int, int>(double, int, int);
My problem is the last part of the matdyn.cpp. I always get error messages like:
error: template-id ‘reserve<int, int, int>’ for ‘void reserve(int, int, int)’ does not match any template declaration
template void reserve<int, int, int>(int, int, int);
How do i write these last two lines properly? Thank you for any help!