Stack Overflow Asked by MR Hones on December 1, 2021
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;
}
}
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.
Answered by Geno C on December 1, 2021
Your declaration differs from definition. In the declaration argument should be of structure pointer type.
void spitThemOut(struct familyFinance * );
Answered by fskoras on December 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP