Hello,

I'm trying to make a circular list by modifying an existing simple-linked list. I'm having a problem when testing whether or not a node is valid. The old code looked like this:

return (elem == NULL);

Now with a circular list I have my sentinel node and what I'm trying to do is to see if the current node is pointing towards the sentinel:

return (elem != sentinel);

However when I try to do this I get a "invalid use of nonstatic data member". Could someone explain to me what does this mean and how to fix it? Thanks!

I need to see the definition of elem and sentinel before we jump to conclusion.

class List
{ 
	class Elem 
	{
	public:
		Elem(int, int, Elem *);
		int nbr, reps
		Elem *next;
	};
  
public:

	class Node
	{
	public:
                //functions
		Elem *elem;
	private:
		Node(Elem *);
		
	};

        //functions
        Elem *sentinel
}

That's roughly the code.

class Node
	{
	public:
                //functions
		Elem *elem;
	private:
		Node(Elem *);
 
	};
 
        //functions
        Elem *sentinel

You just cant compare sentinel to elem under functions defined under class List
elem is an Object defined in class NODE
sentinel is defined under List.
Node is Nested under List
so under List you cant compare this.sentinel to this.elem(Invalid)
but this is correct:

this.sentinel==[Some Node Obj].elem;

Thanks nbaztec! However I solved the problem by comparing the values of the stored items, -1 being the value in the sentinel.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.