Quick problem - return current element in linked list (one line of code)

Class definition:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  class List
{

private:
         struct Node
         {
            int data;
            Node* next;

            Node(): next(NULL){} //define our own default constructor
            Node(int data): next(NULL), data(data){}
         };

typedef struct Node* NodeRef;

NodeRef head;
NodeRef tail;
NodeRef iterator; //points to one node at a time
int size;


I need to write one line of code to return the current element in the list. I think it's done like this?
1
2
3
4
int List::current()
{
   return iterator->data;
}

But it keeps giving me an error.
Can I get quick help please?
Thanks
What is the error that you are getting?
In main:

List L2;
lines to store values

As soon as my tests in main hits " cout << L2.current() << endl;"
I get a message that the project stopped working
Last edited on
This is means that is a runtime error, and I cannot be certain till I see complete code. It seems that the iterator is not initialised to a valid value before the call to current, from the posted code.
Topic archived. No new replies allowed.