I am trying to use template but it does not work, the error is : " previously declared here"
this is my Matrix.h file:
#ifndef MATRIX_H
#define MATRIX_H
template <class T>
class Matrix
{
public:
Matrix(int); // default cunstractor
private:
int rows, columns;
};
#include "Matrix.cpp"
#endif
and this is my Matrix.cpp file
#include "Matrix.h"
#include<iostream>
using namespace std;
template <class T>
Matrix<T>::Matrix(int a) // Default constructor
{
columns = a;
rows = 0;
}
and this is the main file:
#include<iostream>
#include "Matrix.h"
using namespace std;
int main()
{
Matrix<int> m1(5);
return 0;
}
I know the code seems very stupid and simple but I wrote much more, I reduce it to very simple code like this and again it doesn't work. Even I removed
#include "Matrix.cpp"
inside the Matrix.h file but still have problem.