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 returned 1 exit status error'
编译后。
看了很多论坛都没能解决问题。我们最近研究了结构和 类,我不确定我是否误解了一个概念或如何让它发挥作用。
该代码应该通过命令行传递一个文件,然后能够访问它并根据足球运动员的不同统计数据(即 10 名球员)使用冒泡排序进行排序。我不想让我的手被牵着,这就是为什么我把剩下的留给以后再挣扎的原因。该代码在没有函数的情况下在 main 中工作,但是一旦我尝试使用我拥有的代码调用该函数,它就会给我一个错误。
此外,当我尝试将它们作为指针传递时,它给了我无法将 myType* 转换为 myType
更新完整错误:
'In function main':
(.text+0xad): undefined reference to
populateList(wrType*, std::basic_ifstream >&)'
collect2: error: ld returned 1 exit status'
编辑 2:
的代码
'populateList(wrType wide, ifstream in);'
returns 出现以下错误:
在函数‘int main(int, char**)’中:
34:22: error: expected primary-expression before ‘wide’
populateList(wrType wide, ifstream in);
^
34:37: error: expected primary-expression before ‘in’ populateList(wrType wide, ifstream in);
这段代码有很多问题。
struct wrType
{
string name[NUM_PLAYERS];
...
};
您需要一个记录数组,而不是一个并行数组记录。去掉上面struct
.
中的所有[...]
wrType *wide;
您需要这些结构的数组,而不是指针。
wrType wide[NUM_PLAYERS];
populateList(wrType wide, ifstream in);
这不是正确的函数调用语法。
void populateList(wrType wide, ifstream in)
这与之前的声明不符
void populateList(wrType[], ifstream&);
您需要围绕此声明构建整个程序。首先,使您的 populateList
定义与那行
一致
void populateList(wrType[] wide, ifstream& in)
{
}
然后填写正文。请注意,像
这样的行
in >> wide.name[x];
不再正确,您需要更改它们。
编译完全没问题。
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 returned 1 exit status error'
编译后。 看了很多论坛都没能解决问题。我们最近研究了结构和 类,我不确定我是否误解了一个概念或如何让它发挥作用。
该代码应该通过命令行传递一个文件,然后能够访问它并根据足球运动员的不同统计数据(即 10 名球员)使用冒泡排序进行排序。我不想让我的手被牵着,这就是为什么我把剩下的留给以后再挣扎的原因。该代码在没有函数的情况下在 main 中工作,但是一旦我尝试使用我拥有的代码调用该函数,它就会给我一个错误。
此外,当我尝试将它们作为指针传递时,它给了我无法将 myType* 转换为 myType
更新完整错误:
'In function
main': (.text+0xad): undefined reference to
populateList(wrType*, std::basic_ifstream >&)' collect2: error: ld returned 1 exit status'
编辑 2:
的代码'populateList(wrType wide, ifstream in);'
returns 出现以下错误:
在函数‘int main(int, char**)’中:
34:22: error: expected primary-expression before ‘wide’ populateList(wrType wide, ifstream in); ^ 34:37: error: expected primary-expression before ‘in’ populateList(wrType wide, ifstream in);
这段代码有很多问题。
struct wrType { string name[NUM_PLAYERS]; ... };
您需要一个记录数组,而不是一个并行数组记录。去掉上面
struct
. 中的所有wrType *wide;
您需要这些结构的数组,而不是指针。
wrType wide[NUM_PLAYERS];
populateList(wrType wide, ifstream in);
这不是正确的函数调用语法。
void populateList(wrType wide, ifstream in)
这与之前的声明不符
void populateList(wrType[], ifstream&);
[...]
您需要围绕此声明构建整个程序。首先,使您的 populateList
定义与那行
void populateList(wrType[] wide, ifstream& in)
{
}
然后填写正文。请注意,像
这样的行in >> wide.name[x];
不再正确,您需要更改它们。