I have a program that creates a linked list and is required to count the number of elements in the list. This is what I have thus far.
#include <iostream>
using namespace std;
struct listrec
{
int value;
struct listrec *next;
};
listrec e1,e2,e3;
int listsize(listrec);
struct listrec* temp;
int main()
{
e1.value = 4;
e1.next = &e2;
e2.value = 5;
e2.next = &e3;
e3.value = 3;
e3.next = NULL;
int sum = 0;
cout << "The list size is " << listsize(*temp);
system("pause");
return 0;
}
int listsize(listrec *p)
{
struct listrec* temp = p;
int num=0;
do{
temp = temp -> next;
num++;
}while(temp!= NULL);
return num;
}
I get the following error on compilation.
[Linker error] undefined reference to `listsize(listrec)'
Please advise.