簡體   English   中英

ld返回1個帶有傳遞參數的退出狀態錯誤

[英]ld returned 1 exit status error with passing parameters

這樣編譯就可以了。

const int NUM_PLAYERS = 10;

struct wrType
{
string name[NUM_PLAYERS];
string team[NUM_PLAYERS];
int catches[NUM_PLAYERS];
int yards[NUM_PLAYERS];
int td[NUM_PLAYERS];
double ypc[NUM_PLAYERS];
};

void populateList(wrType[], ifstream&);

int main(int args, char* argv[])
{
wrType *wide;
char select;
ifstream in;
in.open(argv[1]);

/*populateList(wrType wide, ifstream in); code causing error*/

}

void populateList(wrType wide, ifstream in)
{   
};

一旦我取消注釋以下代碼

'populateList(wide,in);'

我收到以下錯誤

“ ld返回了1個退出狀態錯誤”

編譯后。 我看過很多論壇,但無法解決問題。 我們最近進入了結構和類,我不確定是否誤解了一個概念或如何使它起作用。

假定該代碼通過命令行傳遞文件,然后可以訪問該文件,並按10位足球運動員的不同統計信息以氣泡排序進行排序。 我不想握着我的手,這就是為什么我把其余的留給我以后去掙扎的原因。 該代碼在沒有函數的情況下仍在main中運行,但是一旦我嘗試使用已有的代碼調用該函數,就會給我一個錯誤。

另外,當我嘗試將它們作為指針傳遞時,它給了我一個無法將myType *轉換為myType的信息。

更新並顯示完整錯誤:

'在函數main': (.text+0xad): undefined reference to populateList(wrType *,std :: basic_ifstream>&)的main': (.text+0xad): undefined reference to 'collect2:錯誤:ld返回1退出狀態'

編輯2:代碼與

'populateList(wrType寬,ifstream輸入);'

返回以下錯誤:

在函數'int main(int,char **)'中:

34:22:錯誤:“寬” populateList(wrType寬,ifstream在)之前的預期主表達式; ^ 34:37:錯誤:在'in'populateList(wrType寬,ifstream在)之前預期的主表達式;

這段代碼有很多問題。

  1.  struct wrType { string name[NUM_PLAYERS]; ... }; 

    您需要一個記錄數組,而不是並行數組的記錄。 刪除上述struct中的所有[...]

  2.  wrType *wide; 

    您需要這些結構的數組,而不是指針。

     wrType wide[NUM_PLAYERS]; 
  3.  populateList(wrType wide, ifstream in); 

    這不是正確的函數調用語法。

  4.  void populateList(wrType wide, ifstream in) 

    這與先前的聲明不符

     void populateList(wrType[], ifstream&); 

您需要圍繞此聲明構建整個程序。 首先,使您的populateList定義與該行一致

void populateList(wrType[] wide, ifstream& in)
{
}

然后填寫身體。 請注意,像

in >> wide.name[x]; 

不再正確,您需要更改它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM