C++ 朋友模板操作符<&书信电报;can';t访问保护类的成员
我正在尝试重载您的C++ 朋友模板操作符<&书信电报;can';t访问保护类的成员,c++,templates,linked-list,encapsulation,friend,C++,Templates,Linked List,Encapsulation,Friend,我正在尝试重载您的朋友声明与运算符的声明不匹配运算符 template <class U> std::ostream& operator << (std::ostream& out, const ListType<U>& list) { if(list.size() > 0) { NodeType<U>* temp = list.head; out << temp -
朋友
声明与运算符的声明不匹配运算符
template <class U>
std::ostream& operator << (std::ostream& out, const ListType<U>& list) {
if(list.size() > 0) {
NodeType<U>* temp = list.head;
out << temp -> info;
temp = temp -> link;
while(temp != NULL) {
out << ", " << temp -> info;
temp=temp -> link;
}
}
return out;
}
template <class T>
class ListType {
protected:
NodeType<T>* head;
size_t count;
public:
ListType(); //DONE
ListType(const ListType&); // DONE
virtual ~ListType(); //DONE
const ListType& operator = (const ListType&); //DONE
virtual bool insert(const T&)=0; //DONE
virtual void eraseAll(); //DONE
void erase(const T&); //DONE
bool find(const T&);
size_t size() const; //DONE
bool empty() const;//DONE
private:
void destroy();//DONE
void copy(const ListType&);//DONE
template <class U>
friend std::ostream& operator << (std::ostream&, const ListType&); //DONE
};
template <class T>
class NodeType {
public:
T info;
NodeType* link;
};
NodeType<int>* ListType<int>::head is protected
error within this context
template <class U>
friend std::ostream& operator << (std::ostream&, const ListType&);
template <class U>
friend std::ostream& operator << (std::ostream&, const ListType<U>&);
// ^^^