gamer1996
gamer1996

Reputation: 5

ld returned 1 exit status error with passing parameters

This compiles perfectly fine.

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)
{   
};

As soon as I uncomment the following code

'populateList(wide, in);'

I get the following error

'ld returned 1 exit status error'

After compiling. I have looked at many forums and have not been able to solve the problem. We recently got into structs and classes and I am not sure if I am misunderstanding a concept or how to get this to work.

The code is supposed pass a file through the command line and then later on be able to access it and sort with bubble sort by different stats of football players which is 10 players. I don't want my hand held which is why I left the rest out for me to struggle with later. The code works without the function and within main but as soon as I try and call the function with the code I have, it gives me an error as stated.

Also when I try to pass them as pointers the it gives me a can't convert myType* to myType

Update with the full error:

'In function main': (.text+0xad): undefined reference topopulateList(wrType*, std::basic_ifstream >&)' collect2: error: ld returned 1 exit status'

Edit 2: The code with

'populateList(wrType wide, ifstream in);'

returns the following error:

In function ‘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);

Upvotes: 0

Views: 148

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119857

There are many problems in this code.

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

    You need an array of records, not a record of parallel arrays. Remove all the [...] in the above struct.

  2. wrType *wide;
    

    You want an array of these structures, not a pointer.

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

    This is not a correct function call syntax.

  4. void populateList(wrType wide, ifstream in)
    

    This doesn't match an earlier declaration

    void populateList(wrType[], ifstream&);
    

You need to build your entire program around this declaration. First, bring your populateList definition into accord with that line

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

then fill in the body. Note that lines like

in >> wide.name[x]; 

are no longer correct, you need to change them.

Upvotes: 1

Related Questions