当我编译我的代码时,我收到一条消息,这是什么意思
When I compile my code I get a message what does it mean
当我编译代码时,收到以下错误消息。他们的意思是什么?我应该担心吗?如果是这样,我该如何解决这个问题?
/tmp/ccK2PEEC.o: In function 'main':
HW2Program.cpp:(.text+0x166): undefined reference to 'spitThemOut(familyFinance)'
collect2: error: ld returned 1 exit status
这是我的代码:
#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;
}
}
您的声明与定义不同。在声明参数应该是结构指针类型。
void spitThemOut(struct familyFinance * );
您的 function declaration
或 prototype
与您 function definition
不匹配。
你的prototype
是这样的:
void spitThemOut(struct familyFinance );
.
那么你的function definition
是这样的:
void spitThemOut (struct familyFinance *ptrHead)
您需要将其更改为void spitThemOut(struct familyFinance* );
。为了让链接器实现spitThemOut()
函数。
当我编译代码时,收到以下错误消息。他们的意思是什么?我应该担心吗?如果是这样,我该如何解决这个问题?
/tmp/ccK2PEEC.o: In function 'main': HW2Program.cpp:(.text+0x166): undefined reference to 'spitThemOut(familyFinance)' collect2: error: ld returned 1 exit status
这是我的代码:
#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;
}
}
您的声明与定义不同。在声明参数应该是结构指针类型。
void spitThemOut(struct familyFinance * );
您的 function declaration
或 prototype
与您 function definition
不匹配。
你的prototype
是这样的:
void spitThemOut(struct familyFinance );
.
那么你的function definition
是这样的:
void spitThemOut (struct familyFinance *ptrHead)
您需要将其更改为void spitThemOut(struct familyFinance* );
。为了让链接器实现spitThemOut()
函数。