I have a Matrix Class defined as follows:
Code:
#include "matrix.h"
template <class Object>
Matrix<Object>::Matrix(int row, int col)
{
rows = row;
cols = col;
array.resize(row);
for(int r = 0; r < row; r++){
array[r].resize(col);
}
}
template <class Object>
void Matrix<Object>::setValue(Object value, int r, int c)
{
array[r,c] = value;
}
template <class Object>
Object Matrix<Object>::GetValue(int r, int c) const
{
return array[r][c];
}
template <class Object>
int Matrix<Object>::GetRow() const
{
return rows;
}
template <class Object>
int Matrix<Object>::GetCol() const
{
return cols;
}
template <class Object>
void Matrix<Object>::OutPut(ostream& out) const{
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; i++){
cout << array[rows][cols] << " ";
}
cout << endl;
}
}
Together with its interface:
Code:
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <vector>
using namespace std;
template <class Object>
class Matrix{
public:
Matrix(int row = 0, int col = 0);
void setValue(Object value, int r, int c);
Object GetValue (int r, int c) const;
int GetRow() const;
int GetCol() const;
void OutPut(ostream& out) const;
private:
vector< vector<Object> > array;
int rows;
int cols;
};
#endif // MATRIX_H
Using a driver programme, I cannot for the life of me instantiate the Matrix object:
Code:
#include <iostream>
#include "matrix.h"
using namespace std;
int main(){
Matrix<int> matrix(2, 2);
return 0;
}
I have a compilation error that says undefined reference to 'Matrix<int>::Matrix(int, int)' and have no clue how to solve this.
Any clues?