在练习模板类的重载输入输出运算符时,编译器提示“无法解析的外部符号”,代码如下:
template <typename T>
class matrix
{
friend ostream& operator<<(ostream &out, const matrix<T> &m);
friend istream& operator>>(sstream &in, matrix<T> &m);
public:
......
private:
int theRows; //矩阵行数
theColumns; //矩阵列数
T *element; //矩阵元素用一维数组存储
};
......
template <typename T>
ostream& operator<<(ostream &out, const matrix<T> &m)
{
for (int i = 0; i < m.theRows; i++)
{
for (int j = 0; j < m.theColumns; ++j)
out << m.element[i * m.theColumns + j] << " ";
out << endl;
}
return out;
}
template <typename T>
istream& operator>>(istream &