Error: Undefined Reference to 'List::add(int)

I've been experiencing the error, "Error: Undefined Reference to 'List::add(int)" along with the same error involving other functions and different classes. What on earth is wrong?? Any advice would be appreciated

Main cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <cstdlib>
#include <iostream>
#include "List.h"
#include "Node.h"

using namespace std;

int main(/*int argc, char *argv[]*/)
{
    List* new_list;
    
    cout << sizeof(new_list) << endl;
    
    new_list->add(5);
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Node .h file and .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef NODE_H
#define NODE_H
#include<string>

class Node{
    public:
        Node();
        Node(int);
        Node(int, Node*);
        int getData();
        Node* getNext();
        void setData(int);
        void setNext(Node*);
    private:
        int data;
        Node* next;    
};

#endif 

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
#include "Node.h" 
#include <cstddef>

Node::Node(){
 data=0;
 next=NULL;   
}

Node::Node(int x){
    data=x;
    next=NULL;
}

Node::Node(int x, Node* n){
    data=x;
    next=n;   
}

int Node::getData(){
    return data;
}
 
Node* Node::getNext(){
    return next;
}   

void Node:: setData(int x){
    data=x;
}

void Node:: setNext(Node* n){
    next=n;   
}


and lastly the list.h and unfinished .cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#ifndef LIST_H
#define LIST_H
#include "Node.h"
using namespace std;
class List : Node
{
    public:
        void add(int);
        void remove();
        void clear();
        int peek();
        bool isEmpty();
        string getName();
        void setName(string);
        
    private:
        Node* headPointer;
        string name;  
};

#endif

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<string>
#include "List.h"

void List::add(int x){
    Node* newNode;
    newNode->setData(x);
    newNode->setNext(headPointer);
    headPointer=newNode;      
}

void List::remove(){
    Node* temp;
    temp=headPointer;
    headPointer=headPointer->getNext();
    delete temp;   
}
It's a linker error. It can't find the definition of List::add(int). If you are using an IDE, make sure that unfinished.cpp has been added to the project.
"Undefined Reference " sounds like a linker error. You're not linking the objects that are compiled from main.cpp and List.cpp properly.
Thanks everyone, i realized theyre not included in my project file!
Topic archived. No new replies allowed.