Template class friend definition

Hi, I've been working with this grammatical problem, which I guess, for about 5 to 6 hours with the book I have and Google but couldn't get a satisfactory answer. In fact I have no clue at all whether what kind of things I should be doing to solve this problem. Specificly, the problem I have is that although I've declared ostream operator << as friend, they still cannot approach the private variables. Can anyone tell me how to fix this messed code?

#include <iostream>
using std::ostream;

template <typename T>
class Container;

template <typename T>
class List;

template <typename T>
class Node;

template<typename T>
ostream& operator<< (ostream&, const Container<T>&);

template<typename T>
ostream& operator<< (ostream&, Node<T>&);

template<typename T>
class Node {
friend class Container<T>;
friend class List<T>;

friend ostream& operator << <> (ostream& out, const Container<T>& container);

friend ostream& operator<< <>(ostream&, Node&);

public:
static int nNode();

private:
Node(T c);
Node(const Node& node);
~Node();

Node *next;
T c;

static int n;
};

template<typename T>
ostream& operator<< <>(ostream& out, Node<T>& node) {
out << node->c;
return out;
}
Last edited on
In the definition, remove the <>:
1
2
3
4
5
6
7
template<typename T>
// ostream& operator<< <> (ostream& out, Node<T>& node)
ostream& operator<< (ostream& out, Node<T>& node)
{
    out << node->c;
    return out;
}


Consider making it const-correct (const Node<T>&).
Topic archived. No new replies allowed.