I've spent the better part of two hours going over my code line by line and I cannot find the problem for the life of me.
#include "stdafx.h"
#include <iostream>
using namespace std;
class NumberList
{
struct ListNode
{
int value;
ListNode *next;
public:
ListNode(int val, ListNode * nextp = NULL)
{
value = val;
next = nextp;
}
};
ListNode * head;
public:
NumberList()
{
head = NULL;
}
void print();
void add(int value);
};
void NumberList::add(int value)
{
if (head == NULL)
head = new ListNode (value);
else
{
//list not empty, find the last node
ListNode *last = head;
while (last->next != NULL)
last = last->next;
//add new value after last node
last->next = new ListNode (value);
}
}
int main()
{
//create a list object
NumberList numList;
//add some values to the list
for (int k = 1; k <= 4; k++)
numList.add(10*k);
//print the list
numList.print();
cout << endl << endl;
return 0;
}
Here's the error I get when I try to compile.
*error LNK2019: unresolved external symbol "public: void __thiscall NumberList::print(void)" (?print@NumberList@@QAEXXZ) referenced in function _main*
I also get this, but I believe they are caused by the same error in my numList.print.
1>D:\CS-160\pc17try2\Debug\pc17try2.exe : fatal error LNK1120: 1 unresolved externals
Any help would be great, I've looked through my book and video notes and I don't believe I should be having any issues; very confused.