Originally Posted by
CornedBee
The Node inner class should be private.
You are totally correct. Thanks
One more little issue if i have
Code:
class LinkedList
{
public:
friend class Iterator;
class Iterator
{
public:
friend class LinkedList;
// constructors
Iterator(const LinkedList *list);
~Iterator();
// methods
void Next();
void Start();
bool IsValid();
Entry * GetValue();
private:
const LinkedList *m_list; // the list we're iterating
LinkedList::Node *m_current; // current node we're in
};
// constructors
LinkedList(void);
~LinkedList(void);
// metods
void Append(const Entry val);
void Prepend(const Entry val);
void RemoveHead();
void RemoveTail();
void RemoveNode(Iterator *it);
Entry Head();
private:
struct Node
{
public:
Node(Entry val);
Node();
Node *next;
Node *previous;
Entry val;
};
Node *m_head; // head of the linked list
Node *m_tail; // tail fo the linked list
LinkedList(const LinkedList &){}; // enforce that the user will not pass by value a linked list
};
this fails because in the nested class Iterator i use a Node, and the compiler only sees the declaration of the inner struct Node after the declaration of Iterator. I know this is solved with forward declarations, or by declaring the Node struct before the iterator class.
however how do i foward declare the Node struct;
1º before the LinkedList class like
Code:
struct LinkedList::Node; //this was my 1º though but it fails
struct Node; also fails
one way it doesn't fail is if i declare inside of the LinkedList class like
Code:
public:
struct Node;
...
...
however i need to forward declare it in a private section or i would get the warning
"Warning 1 warning C4240: nonstandard extension used : access to 'LinkedList::Node' now defined to be 'private', previously it was defined to be 'public'"
but if i declare it in a private section im better of doing
Code:
class LinkedList
{
private:
struct Node {....};
...
public
class Iterator {.....};
etc...
This is more a syntax question however how to forward declare the struct Node ?
Once more thanks for all feedback