overloading problem with linked list

hi guys I recently asked a question about overloading the post and pre fix incremental operators with enums but now I am trying to implement a way to get the current node of a linked list but I get an error when trying to overload,the syntax looks correct to me,

but this is what the compiler throws at me

C:\Users\User\doublyLinkedList\main.cpp|78|error: declaration of 'operator++' as non-function|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  #include <iostream>

using namespace std;


class Node{

   public:
       int number;
       Node* next;
       Node* previous;

       Node(int n,Node* ne,Node* p){

           number = n;
           next = ne;
           previous = p;

       }

};


class List{

public:


   Node* head = NULL;
   Node* tail = NULL;
   Node* now;


   List(){}

   void addNode(int number){

      Node* newNode = new Node(number,head,NULL);

      if(head != NULL){

        head->previous = newNode;
      }

      head = newNode;
      now = head;

      if(tail == NULL){

        tail = newNode;
      }
   }

   void printList(){

      Node* current = head;

      while(current != NULL){

        cout << current->number << endl;
        current = current->next;

      }
   }

   void reverseList(){

    Node* current = tail;

    while(current != NULL){

        cout << current->number << endl;
        current = current->previous;
    }

   }

   Node& operator++(List& ls){





   }

};

int main()
{

    List list;
    list.addNode(1);
    list.addNode(2);
    list.addNode(3);

    list.reverseList();

}
Last edited on
******* EDIT

sorry guys I had the ampersand in the wrong place should,stupid mistake

but I am still having a problem it is telling me that I need an int in the arguments to verload the postfix operator but the thing is I am not trying to overload the postfix operator I am trying the pre fix operator

Last edited on
I need an int in the arguments to verload the postfix operator but the thing is I am not trying to overload the postfix operator I am trying the pre fix operator

In that case the function argument list should be empty (Node& operator++()):
http://en.cppreference.com/w/cpp/language/operator_incdec

Note: you can use ‘nullptr’ in place of ‘NULL’.
Topic archived. No new replies allowed.