模板,'out << "("' 中的 'operator<<' 不匹配

Templates, no match for 'operator<<' in 'out << "("'

我正在尝试为模板重载 << 运算符,但出现此错误。

我想要实现的是重载运算符 << 它将提供左括号,所有选项卡项由“,”分隔,右括号为 'out'。

这是我的部分代码:

template <typename T>
class arry{
    T *tab;
    int n;
public:
    arry(T *t, int x) : n(x),tab(t){};
    friend std::ostream & operator << (const std::ostream & out, const arry<T> & t)
    {
        out << "(";
        for(int i=0;i<t.n;i++){
            out << t.tab[i];
            if(i < t.n-1)
                out << ", ";
        }
        out << ")";
        return out;
    }
};

最糟糕的是我的构建日志为我提供了 230 行错误,此时我有点困惑。

操作符是用来修改流的,所以第一个参数不能是const引用。改成

friend std::ostream & operator << (std::ostream & out, const arry& t)