我有以下内容:

using namespace std;

template<class T> class olsm;
template<class T> istream& operator>>(istream& in, olsm<T>& x);
template<class T> ostream& operator<<(ostream& out, olsm<T>& x);

template <class T>
class olsm {

    friend istream& operator>> <> (istream& in, olsm& x);
    friend ostream& operator<< <> (ostream& out, olsm& x);

    public:
        class node {
            public:
        };

        ///Other stuff
};

////More stuff

template<class T>
ostream& operator<<(ostream& out, olsm<T>& x) {

    olsm<T>::node* rowNode = x;

    //Even more stuff!

    return out;
}

但是当我尝试编译时,我得到了,
error: 'rowNode' was not declared in this scope

这很奇怪,因为我在尝试声明该错误的行上收到错误。有人知道为什么吗?

最佳答案

olsm<T>::node*是一个从属名称(取决于模板参数)。您需要编写typename olsm<T>::node*来告诉编译器它引用了一个类型(默认情况下,编译器将假定它引用了一个成员)。

有关详细说明,请参见this question

07-27 23:50