-1

When I compile my code, I get the following error messages. What do they mean? Should I be worried? If so, how do I go about fixing this?

/tmp/ccK2PEEC.o: In function 'main':
HW2Program.cpp:(.text+0x166): undefined reference to 'spitThemOut(familyFinance)'
collect2: error: ld returned 1 exit status

Here is my code:

#include <iostream>
#include <iomanip>
#include <fstream>
    
using namespace std;

struct familyFinance{                     
    int acctNos; float Balance; familyFinance *nextNodePointer;
    familyFinance *ptrHead;  familyFinance *dynFinancePtr;
};
    
void spitThemOut(struct  familyFinance ); 
    
int main() {
    ifstream Lab3DataFileHandle;
     
    familyFinance *ptrHead=nullptr;
    familyFinance *dynFinancePtr=nullptr;
    familyFinance *tempPtr;
    tempPtr=ptrHead;
    
    Lab3DataFileHandle.open("Lab5Data.txt");
    while (!Lab3DataFileHandle.eof( )) {
        familyFinance *dynFinancePtr= new familyFinance;
    
        Lab3DataFileHandle >> dynFinancePtr->acctNos;
        Lab3DataFileHandle >> dynFinancePtr->Balance;
     
        familyFinance *nextNodePointer = nullptr;
        if (ptrHead == nullptr)  
            ptrHead = dynFinancePtr;
        else {      
            tempPtr =  ptrHead;  
            while  (tempPtr -> nextNodePointer != nullptr )
                tempPtr = tempPtr->nextNodePointer;
            tempPtr->nextNodePointer = dynFinancePtr; 
        }
    }
    Lab3DataFileHandle.close();
    
    spitThemOut ( *ptrHead);

    return 0;
}
         
void spitThemOut (struct  familyFinance *ptrHead) {
    cout << showpos;
    familyFinance *nextNodePointer;
    nextNodePointer = ptrHead;

    while (nextNodePointer) {
        cout << "Acct, Balance: " << setw(3)
             << nextNodePointer->acctNos << " " << nextNodePointer->Balance << endl;
    }
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
MR Hones
  • 61
  • 9
  • the linker can't find a suitable implementation of `spitThemOut` – Alberto Sinigaglia Jul 22 '20 at 22:22
  • Your prototype of `spitThemOut()` does not match the definition. A struct is a different type than a pointer to that struct. – Fred Larson Jul 22 '20 at 22:27
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mansoor Jul 22 '20 at 22:44

2 Answers2

2

Your declaration differs from definition. In the declaration argument should be of structure pointer type.

void spitThemOut(struct familyFinance * );

fskoras
  • 68
  • 7
1

Your function declaration or prototype does not match you function definition.

Your prototype is this:

void spitThemOut(struct familyFinance );.

Then your function definition is this:

void spitThemOut (struct familyFinance *ptrHead)

You need to change it to void spitThemOut(struct familyFinance* );. In order for the linker to implement the spitThemOut() function.

Geno C
  • 1,401
  • 3
  • 11
  • 26