0

I have a small program I have written that accepts user input and creates a linked list. I am encountering an error when building that seems to relate to the passing of the HeadPointer into the print function. The error is as follows:

undefined reference to `PrintList(PetData*)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

If anyone could point(put not intended) me in the right direction or even explicitly give me a fix I would really appreciate it. Source Code:

#include <iomanip>
#include <string>
#include <iostream>


using namespace std;

struct PetData{
    int IdNumber;
    string PetType;
    PetData *link;
};

PetData * HeadPointer=NULL;

void InsertItem(int, string, PetData*);

void PrintList(PetData*);

int main(){
    int init_IdNumber;
    string init_PetType;
    PetData * CRP = NULL;

    char cflag = 'Y';
    while (toupper(cflag) == 'Y'){
        cout << "Please Enter an ID Number: " << endl;
        cin >> init_IdNumber;

        cout << "Please Enter a Pet Type: " << endl;
        cin >> init_PetType;

        CRP = new PetData;

        InsertItem(init_IdNumber,init_PetType,CRP);
        HeadPointer=CRP;

        cout << "Would you like to enter another? (Y/N)" << endl;
        cin >> cflag;


    };


    PrintList(HeadPointer);



    return 1;
};

void InsertItem(int init_IdNumber, string init_PetType, PetData* CRP){
    CRP->PetType = init_PetType;
    CRP->IdNumber = init_IdNumber;
    CRP->link = HeadPointer;
};

void PrintList(){
    while(HeadPointer != NULL){
        cout << HeadPointer->PetType << "\t" << HeadPointer->IdNumber << endl;
        HeadPointer = HeadPointer->link;
    }

};

Before anyone brings it up, this is not a homework assignment. It was something my professor suggested we create independently in preparation for a future midterm assignment.

Thanks!

FantasticSponge
  • 105
  • 1
  • 1
  • 9

1 Answers1

2

The function declaration and definiton is not matching.

The prototype of the function is void PrintList(PetData*); and the definition is void PrintList(). This is why it is not matching.

There is the corrected code

void PrintList(PetData* HeadPointer){
    while(HeadPointer != NULL){
        cout << HeadPointer->PetType << "\t" << HeadPointer->IdNumber << endl;
        HeadPointer = HeadPointer->link;
    }
knightrider
  • 2,063
  • 1
  • 16
  • 29