Passing an object to a function?

Im having a problem passing a specif object of a class to a function. I am getting error codes left an right. Will someone be willing to help me. My code is below with a message from a Professor of mine.

Her message:
"ERROR: printone is using a global data structure. It should receive the single object to print as a parameter, rather than receiving the subscript as a parameter. You must declare the array of object inside main. Class definitions are global, but not actual variables."




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//search function
void findlastname(Juventus team[], int n, string lastname)
{
     
     for(int count=0;count<n;count++){
          if(lastname==team[count].personal.last)
               printone(team[count]);
          
     }
          return;
}
//printone
void printone(Juventus team[count]){

    
     cout<<"First name: "<<team[count].personal.first<<endl;
     cout<<"Last name: "<<team[count].personal.last<<endl;
     cout<<"Age: "<<team[count].personal.age<<endl;
     cout<<"Player Position: "<<team[count].player.position<<endl;
     cout<<"Goals scored this season: "<<team[count].player.goals<<endl;
     cout<<"Assists this season: "<<team[count].player.assists<<endl<<endl;
     
     return;
}
Who is she?? Your teacher?

Anyway, you are being told that the printone() function needs to receive a single object. Why then are you trying to put an entire array up there?? Don't receive an entire array, just receive a single Juventus object.
Last edited on
Sorry. "She" is my prof. Here is the thing. I am stumped on how to pass just a single object from Juventus.
Well, first things first. White noise (spaces, tabs, returns, etc.) aren't allowed in variable names.

Second, you actually have to declare an instance of team.

Third, you have a message from your instructor that describes errors in places that you haven't posted code for.
I also assumed that Juventus was the name of a class. In other words, I assumed you were declaring a parameter called team that was an array of objects of type Juventus. I know, it doesn't make sense in the context of soccer, but that's what I read in my C++ brain. You need to tell us the type of object that you need to give to printone().
Topic archived. No new replies allowed.