1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Confused on simple error

Discussion in 'C++' started by Tinymittenz, Sep 1, 2011.

  1. Tinymittenz

    Tinymittenz New Member

    Joined:
    Sep 1, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    It seems I have been looking at this code for hours on in and I feel lost in the woods. I know it might be such an easy simple error to correct, but I cant seem to figure it out. Any help will be greatly appreciated.

    Code:
    [SIZE=2][COLOR=#0000ff]
    [SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]<stdlib.h>[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]<string>[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]<iostream>[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] std::cout;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] std::string;[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// node object for the linked list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Node {[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] data;[/SIZE]
    [SIZE=2]Node* link;[/SIZE]
    [SIZE=2]};[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// implement a singly linked list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LinkedList {[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE]
    [SIZE=2]Node* front; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// pointer to the front of the linked list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]Node* back; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// pointer to the last node in the linked list[/COLOR][/SIZE]
    [/COLOR][/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// constructs an empty list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]LinkedList() {[/SIZE]
    [SIZE=2]front = back = NULL;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// deletes the list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]~LinkedList() {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// remove objects from the list as long as list is not empty[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](Length() > 0) {[/SIZE]
    [SIZE=2]RemoveFront();[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
     
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// inserts a node at the front of the list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] InsertFront([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] newValue) {[/SIZE]
    [SIZE=2]Node* newNode = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Node;[/SIZE]
    [SIZE=2]newNode->data = newValue;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (front == NULL) {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// list must be empty so make front & back point to new node[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]front = back = newNode;[/SIZE]
    [SIZE=2]newNode->link = NULL;[/SIZE]
    [SIZE=2]} [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// list is not empty so insert between front and first node[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]newNode->link = front;[/SIZE]
    [SIZE=2]front = newNode;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// removes a node from the front of the list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] RemoveFront() {[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] returnVal;[/SIZE]
    [SIZE=2]Node *temp;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (front != NULL) {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// list is not empty so remove & return first node[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]returnVal = front->data;[/SIZE]
    [SIZE=2]temp = front;[/SIZE]
    [SIZE=2]front = front->link;[/SIZE]
    [SIZE=2]} [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// list is empty just return 0[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]returnVal = 0;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] returnVal;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// returns the length of the list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Length() {[/SIZE]
    [SIZE=2]Node* p;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] count = 0;[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// loop through each node in the list until we find a null value[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p = front; p != NULL; p = p->link) {[/SIZE]
    [SIZE=2]count++;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] count;[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// outputs a string containing all the data values in the list[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Output() {[/SIZE]
    [SIZE=2]Node* p;[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// loop through each node in the list until we find a null value[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p = front; p != NULL; p = p->link) {[/SIZE]
    [SIZE=2]cout << p->data << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]", "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//use inheritance to create a Set Cclass from the LinkedList class[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Set: [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LinkedList {[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//insert a new value only if it is unique (not already in the set)[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Insert([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] newValue){[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] duplicate = Search(newValue);[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (duplicate == -1)[/SIZE]
    [SIZE=2]InsertFront(newValue);[/SIZE]
    [SIZE=2]}[/SIZE]
     
     
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//make this union of two sets[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Union(Set& a, Set& B){[/SIZE]
    [SIZE=2]Node*p;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p = a.front; p != NULL; p = p->link){[/SIZE]
    [SIZE=2]Insert(p->data);[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p = b.front; p != NULL; p = p->link){[/SIZE]
    [SIZE=2]Insert(p->data);[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//make this intersection of two sets[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intersection(Set& a, Set& B){[/SIZE]
    [SIZE=2]Node* p;[/SIZE]
    [SIZE=2]Node* q;[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p = a.front; p != NULL; p = p->link)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (q = b.front; q != NULL; q = p->link)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (p->data == q->data)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2]Insert(p->data);[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]};[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] main (){[/SIZE]
    [SIZE=2]Set setA, setB, setUnion, setIntersection;[/SIZE]
    [SIZE=2]setA.Insert(5);[/SIZE]
    [SIZE=2]setA.Insert(2);[/SIZE]
    [SIZE=2]setA.Insert(3);[/SIZE]
    [SIZE=2]setA.Insert(5);[/SIZE]
    [SIZE=2]setA.Insert(2);[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Contents of setA: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setA.Output();[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setB.Insert(1);[/SIZE]
    [SIZE=2]setB.Insert(2);[/SIZE]
    [SIZE=2]setB.Insert(4);[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Contents of setB: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setB.Output();[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setUnion.Union(setA, setB);[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Contents of setA union setB: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setUnion.Output();[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setIntersection.Intersection(setA, setB);[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Contents of setA intersection setB: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]setIntersection.Output();[/SIZE]
    [SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]system([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"PAUSE"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2]}[/SIZE]
    
    This is my error: error C2504: 'LinkedList' : base class undefined
     
  2. priyatendulkar

    priyatendulkar New Member

    Joined:
    Jun 20, 2011
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    0
    hi,

    U have declared class LinkedList incorrectly..
    Add the following closing brace and semiclon at the end of the class
    ie after
    void Output() {
    Node* p;
    // loop through each node in the list until we find a null value
    for (p = front; p != NULL; p = p->link) {
    cout << p->data << ", ";
    }
    }

    }; //add this....
     

Share This Page