Hi,
I am getting a build error when I break the code in the book down to a .h file and 2 .cpp files and I'm not sure why. I am following the steps in the book fairly accurately I think. I run the program through orig.cpp and I get the following build error.
mingw32-g++.exe -c X:\Users\Notneeded\jumpcplusplus\orig.cpp -o X:\Users\Notneeded\jumpcplusplus\orig.o
mingw32-g++.exe -o
X:\Users\Notneeded\jumpcplusplus\orig.exe X:\Users\DSoutherland\jumpcplusplus\orig.o
X:\Users\Notneeded\jumpcplusplus\orig.orig.cpp.text+0x91): undefined reference to `addNode(Node*, int)'
X:\Users\Notneeded\jumpcplusplus\orig.orig.cpp.text+0xb4): undefined reference to `printList(Node const*)'
collect2.exe: error: ld returned 1 exit status
I thought by #include "linkedlist.h" in the orig.ccp code it would allow communication between the linkedlist.h and the linkedlist.cpp but it doesn't appear that the orig.cpp file has access to the logic of the functions.
Wondering what I am missing?
(s), 0 warning(s) (0 minute(s), 1 second(s))
linkedlist.h
Code:
struct Node
{
Node *p_next;
int value;
};Node *addNode (Node* p_list, int value);
void printList (const Node* p_list);
linkedlist.cpp
Code:
#include <iostream>
#include "linkedlist.h"
using namespace std;
Node *addNode (Node* p_list, int value)
{
Node *p_new_node = new Node;
p_new_node->value = value;
p_new_node->p_next = p_list;
return p_new_node;
}
void printList (const Node* p_list)
{
const Node* p_cur_node = p_list;
while (p_cur_node != NULL)
{
cout << p_cur_node->value << endl;
p_cur_node = p_cur_node->p_next;
}
}
orig.cpp
Code:
#include <iostream>
#include "linkedlist.h"
using namespace std;
int main ()
{
Node *p_list = NULL;
for ( int i = 0; i<10; ++i)
{
int value;
cout << "Enter value for list node: ";
cin >> value;
p_list = addNode(p_list, value);
}
printList(p_list);
}