对于一项作业,我需要能够创建一个模板化的朋友类,其余的程序都可以正常工作,但是我无法越过错误。我提供了用于定义这两个类的代码以及这些错误的照片。如果我需要更具体的问题,请告诉我,但老实说,我对模板一无所知。谢谢。
template<class T>
class Node{
friend class NodeStack;
public:
Node();
Node(const T & data, Node<T> * next = NULL);
T & data();
const T & data() const;
public:
Node<T> * m_next;
T m_data;
};
template<class T>
class NodeStack{
template<class U>
friend std::ostream & operator<< (std::ostream & os, const NodeStack<T> & nodeStack);
public:
NodeStack();
NodeStack(size_t count, const T & value = T() );
NodeStack(const NodeStack<T> &other);
~NodeStack();
NodeStack<T> & operator=(const NodeStack<T> & rhs);
T & top();
const T & top() const;
void push(const T & value);
void pop();
size_t size() const;
bool empty() const;
bool full() const;
void clear();
void serialize(std::ostream & os) const;
private:
Node<T>* m_top;
};
将您的朋友声明更改为
friend class NodeStack<T>;
我应该做的把戏。