A
Adam Parkin
Hello, all I'm having a problem with friend functions in a templatized Queue
class I'm writing using linked lists. The problem is that I can't get the
friend function to be able to access private data from the class. Here's
the gist of the code:
template <class T>
struct NodeType
{
T data;
NodeType<T> * link;
};
template <class T>
class Queue1
{
friend ostream & operator<< (ostream & lhs, const Queue1 <T> & rhs);
// some public methods & stuff here
private:
NodeType <T> * head;
NodeType <T> * tail;
};
template <class T>
ostream & operator<< (ostream & lhs, const Queue1 <T> & rhs)
{
NodeType <T> * pIterator = rhs.tail;
return &lhs;
}
The problem I get is that in the operator<< function my compiler (Visual C++
6) is reporting:
'tail' : cannot access private member declared in class 'Queue1<char>'
(this is of course using a driver program that declares a Queue1<char>
object).
Any suggestions would be appreciated.
Adam
class I'm writing using linked lists. The problem is that I can't get the
friend function to be able to access private data from the class. Here's
the gist of the code:
template <class T>
struct NodeType
{
T data;
NodeType<T> * link;
};
template <class T>
class Queue1
{
friend ostream & operator<< (ostream & lhs, const Queue1 <T> & rhs);
// some public methods & stuff here
private:
NodeType <T> * head;
NodeType <T> * tail;
};
template <class T>
ostream & operator<< (ostream & lhs, const Queue1 <T> & rhs)
{
NodeType <T> * pIterator = rhs.tail;
return &lhs;
}
The problem I get is that in the operator<< function my compiler (Visual C++
6) is reporting:
'tail' : cannot access private member declared in class 'Queue1<char>'
(this is of course using a driver program that declares a Queue1<char>
object).
Any suggestions would be appreciated.
Adam