0

嗨,这是我第一次在这里发帖,我对编码比较陌生,所以我遇到了很多问题。大多数时候我可以自己学习如何修复错误,但现在我想我只是遇到了数组和结构的主要障碍。目前,编译时会给我

undefined reference to `buildArrays(std::string, int, int, int)'

问题是,每次我尝试在 main 函数中“修复”buildArray 调用者时,我都会遇到这个错误,将字符串 PlaName 更改为 char PlaName [25] 在结构 Players 中以某种方式工作但不会改变错误。无论如何我可以尝试更改代码,以便数组可能会从一个函数调用到另一个函数?我为这个错误查找的大多数信息主要是关于链接器,这没有帮助。

顺便说一句,我的作业要求我从文件创建一个数组,从函数中调用它,在主函数中,并在其余的主函数中使用该数组。我不知道该程序是否有效,因为我无法通过未定义的引用错误。这里大部分的程序:

using namespace std;

struct Players
{
    string PlaName;
    int PlaGoal;
    int PlaAssist;
    int Points;
};

int buildArrays( string, int, int, int);
void printArrays( string, int, int, int, int);
void sortArrays( string, int, int, int, int);

int main()
{
Players player;

   buildArrays(player.PlaName,player.PlaGoal,player.PlaAssist,player.Points); //this is the error

  cout<<"Chicago Blackhawks UNSORTED Report;";


}

int buildArrays( string playerNames[], int goals[], int assists[], int rating[] ) //this function's format is required for the homework
{
    ifstream inFile;

    inFile.open("hockey.txt");
    if (inFile.fail())
        {
        cout<<"The hockey.txt input file did not open";
        exit(-1);
        }

    while (inFile)
        for(int i = 0; i <= 25; i++)
        {
        inFile >> playerNames[i]
               >> goals[i]
               >> assists[i]
               >> rating[i];
        cout<<playerNames[i]<<goals[i]<<assists[i]<<rating[i];
        }
        inFile.close();
        return 0;
}
4

1 回答 1

0

问题似乎是您的 buildArrays 函数原型与您的函数定义不匹配。您的函数接受数组,但您的原型不使用数组语法。将您的原型更改为如下所示:

buildArrays( string[], int[], int[], int[] ) ;

Also your main() function needs to pass in arrays into the buildArrays() function. Creating a single struct and passing each member will not be sufficient. Perhaps you need to rework how you organize your data if you have to use the buildArrays() function format for your homework. Perhaps create separate arrays for each piece of player data and then create an array of structs after calling buildArrays().

于 2013-03-30T00:35:01.043 回答