Odd error: no match for operator ... in ....

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
#include <iostream>

using namespace std;

class Node
{
    private:
        Node * nextNode;
        Node * prevNode;
        int data;


    public:

        void setData(int data)
        {
            this->data = data;

        };

        int getData()
        {
            return data;

        };
        Node *getNext()
        {
            return nextNode;
        };
        Node *getPrev()
        {
            return prevNode;

        };
        void setNext(Node *anotherNode)
        {
            this->nextNode = anotherNode;

        };
        void setPrev(Node *anotherNode)
        {

            this->prevNode = anotherNode;
        };
};




int main()
{
    Node * firstNode = new Node;
    Node * secondNode = new Node;
    Node * thirdNode = new Node;
    Node * fourthNode = new Node;
    Node * fifthNode = new Node;

    firstNode->setData(2);
    firstNode->setNext(secondNode);

    secondNode->setData(10);
    secondNode->setNext(thirdNode);

    thirdNode->setData(3);
    thirdNode->setNext(fourthNode);

    fourthNode->setData(2);
    fourthNode->setNext(fifthNode);

    fifthNode->setData(5);



    cout << firstNode->getData;
         return 0;
}


My error is
error: no match for operator << in std::cout << firstNode->Node::getData

Not sure why this is. Can anyone explain?
You're missing the brackets cout << firstNode->getData();
wow. I am retarded.
You're doing linked lists in C++. I wouldn't call that retarded :)

fun fact: VB does not require brackets for function calls that have no arguments!
So now I am getting a segmentation fault.

I know its probably b/c of a dangling pointer right?
But I dont understand why. If I comment out the call to remove duplicates, it compiles then gives segmentation fault in console.
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>

using namespace std;

class Node
{

    public:
        Node * nextNode;
        Node * prevNode;
        int data;



        void setData(int data)
        {
            this->data = data;

        };

        int getData()
        {
            return data;

        };
        Node *getNext()
        {
            return nextNode;
        };
        Node *getPrev()
        {
            return prevNode;

        };
        void setNext(Node *anotherNode)
        {
            this->nextNode = anotherNode;

        };
        void setPrev(Node *anotherNode)
        {

            this->prevNode = anotherNode;
        };
        void removeDuplicates(Node * myPtr)
        {
            cout << "I am in";

            Node * nodePtr1 = myPtr;
            Node * nodePtr2 = nodePtr1;
            Node * temp = nodePtr2;

            for(int a=0; a<5; a++)
            {

                for(int a=0; a<5; a++)
                {
                    nodePtr2 = nodePtr2->getNext();
                    temp = nodePtr2;
                    if((nodePtr2->getData()) == (nodePtr1->getData()))
                       {
                           nodePtr2 = nodePtr2->getNext();
                           temp->setNext(nodePtr2);
                       }

                }
                nodePtr1 = myPtr->getNext();
            }
        };
};




int main()
{
    Node * firstNode = new Node;
    Node * secondNode = new Node;
    Node * thirdNode = new Node;
    Node * fourthNode = new Node;
    Node * fifthNode = new Node;



    firstNode->setData(2);
    firstNode->setNext(secondNode);

    secondNode->setData(10);
    secondNode->setNext(thirdNode);

    thirdNode->setData(3);
    thirdNode->setNext(fourthNode);

    fourthNode->setData(2);
    fourthNode->setNext(fifthNode);

    fifthNode->setData(5);

     Node * myPtr = firstNode;
     cout << myPtr->getData();

    cout << myPtr;

   // myPtr->removeDuplicates(myPtr);

/*
    while(myPtr != 0)
   {
       cout << myPtr->getData() << " -> ";
       myPtr = myPtr->getNext();

   }


*/

         return 0;
}
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
        void removeDuplicates(Node * myPtr) // ¿why is this a member function?
        {
            cout << "I am in";

            Node * nodePtr1 = myPtr;
            Node * nodePtr2 = nodePtr1;
            Node * temp = nodePtr2;

            for(int a=0; a<5; a++) //executes 5 times
            {

                for(int a=0; a<5; a++) //executes 5 times (total 25)
                {
                    nodePtr2 = nodePtr2->getNext();
                    temp = nodePtr2;
                    if((nodePtr2->getData()) == (nodePtr1->getData()))
                       {
                           nodePtr2 = nodePtr2->getNext();
                           temp->setNext(nodePtr2); //possible memory leak
                       }

                }
                nodePtr1 = myPtr->getNext();
            }
        }
There is a difference between a Node and a List.
I built it and it ran fine for me (Visual Studio 2005).

I know its probably b/c of a dangling pointer right?

Yeah, it's probably because the five Node pointers weren't de-allocated. It's probably implementation specific in terms of whether or not to raise an error if memory is left on the heap on program termination. If you delete the five Node*s does the segmentation fault go away?
Topic archived. No new replies allowed.