Вот мой файл Matrix.cpp. (есть отдельный файл Matrix.h)
#include <iostream>
#include <stdexcept>
#include "Matrix.h"
using namespace std;
Matrix::Matrix<T>(int r, int c, T fill = 1)
{
if (r > maxLength || c > maxLength) {
cerr << "Number of rows and columns should not exceed " << maxLen << endl;
throw 1;
}
if (r < 0 || c < 0) {
cerr << "The values for the number of rows and columns should be positive" << endl;
throw 2;
}
rows = r;
cols = c;
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
mat[i][j] = fill;
}
Это дает следующее
ошибка: недопустимое использование имени шаблона "Matrix" без списка аргументов
В чем проблема в моем коде?
РЕДАКТИРОВАТЬ: Матрица класса определяется с template<class T>
EDIT:
Вот мой файл Matrix.h:
#include <iostream>
#include <math.h>
#define maxLength 10;
using namespace std;
template <class T>
class Matrix
{
public:
Matrix(int r, int c, T fill = 1);
private:
int rows, cols;
T mat[10][10];
};
А вот файл Matrix.cpp:
#include <iostream>
#include <stdexcept>
#include "Matrix.h"
using namespace std;
template<class T>
Matrix<T>::Matrix(int r, int c, T fill = 1)
{
}
Это дает следующую ошибку:
Matrix.cpp: 12: 43: ошибка: аргумент по умолчанию для параметра 3
Rix Matrix :: Matrix (int, int, T) ’Matrix.h: 16: 3: ошибка: после предыдущего
спецификация в «Matrix :: Matrix (int, int, T)»
Что не так в моем коде?