!= function linked list

Hi,
First time using both pointers and iterators. I am stuck on overloading the != operator for my iterator. I get segmentation fault when I use the one I tried implementing. Please help.

List.h:
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
#ifndef LIST_H
#define LIST_H

class Sorted_List
{
private:
    class Node
    {
    public:
        int value;
        Node* prev;
        Node* next;
    };
    Node* first;
    Node* last;
    
public:
    //constructors and functions
    
    class Iterator
    {
    public:
        Iterator(Node* n);
        Iterator& operator++();
        bool operator!=(Iterator const& right) const;
        int operator*() const;
    private:
        Node* it;
    };
    
    Iterator begin();
    
    Iterator end();
};
#endif 


List.cc:
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
#include "List.h"
//implementations

Sorted_List::Iterator:: Iterator(Node* n) : it{n}
{
}

Sorted_List::Iterator Sorted_List:: begin()
{
    return Iterator(first->next);
}

Sorted_List::Iterator Sorted_List:: end()
{
    return Iterator(last);
}

Sorted_List::Iterator& Sorted_List::Iterator::operator++()
{
    it=it->next;
    return *this;
}

bool Sorted_List::Iterator:: operator!=(Iterator const& right) const
{
    if (*this != right)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int Sorted_List::Iterator:: operator*() const
{
    return it->value;
}
Line 26: How do you tell that two iterators are not equal?
Topic archived. No new replies allowed.