使用模板 C++ 的友元函数语法错误

error in friend function syntax using templates c++

本文关键字:友元 函数 语法 错误 C++      更新时间:2023-10-16

我正在编写一个表示矩阵的类,遇到了一个错误:倒数第二行的"<"标记之前的"预期')'"。

template<typename T>
class Matrix;
template<typename T>
Matrix<T> operator-(const Matrix<T> &self);
template<typename T>
ostream & operator<<(ostream &out, const Matrix<T> &matrix);
template<typename T> class Matrix
{
public:
    friend ostream & (operator<<<> )(ostream &out, const Matrix &matrix);
    friend Matrix (operator-<>)(const Matrix &self); //error here
};

一定是使用 Linux GCC 的 eclipse 的一个错误。通过使用不同的编译器进行编译来解决它。