Why am I getting linker errors when trying to compile this code, this is basically a code for a template class matrix that is complex & matrix is a square matrix so if size "3" is entered it means a matrix of [3][3] but somehow it gives me errors, any help?
#include <iostream>
#include <iomanip>
using namespace std;
template <class T>
class matrix
{
private:
T** real;
T** imag;
int size;
public:
matrix(int = 0);
friend ostream& operator<<(ostream& out, matrix<T>);
};
// constructor
template <class T>
matrix<T>::matrix(int length)
{
size = length;
real = new T*[size];
for (int i = 0; i < size; i++)
real[i] = new T[size];
imag = new T*[size];
for (int i = 0; i < size; i++)
imag[i] = new T[size];
cout << "Enter real elements of matrix: ";
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
cin >> real[i][j];
cout << "Enter imag elements of matrix: ";
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
cin >> imag[i][j];
}
// functions defined here
template <class T>
ostream& operator<<(ostream& out, matrix<T> arg)
{
out << showpos;
for (int i = 0; i < arg.size; i++)
for (int j = 0; j < arg.size; j++)
out << arg.real[i][j] << arg.imag[i][j] << " ";
out << endl;
return out;
}
int main()
{
matrix <int> obj1(3);
cout << obj1;
}