Error: Conversion from scalar to nonscalar

  • Thread starter Thread starter VinceStolen
  • Start date Start date
  • Tags Tags
    Error Scalar
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 21K views
VinceStolen
Messages
9
Reaction score
0
Hi I am writing a code and I am getting a compiler error that I can not seem to figure out. I have limited programming knowledge and I have come here for help. This is the section of code I feel is relevant.

struct Player {
string name;
int goals;
int assists;
};

int find_player(Player , int , string);
void print_player( const Player &);
int main() {

Player p[50]
int size = 0;
string find;

count << endl; << "Please enter players name: "
cin >> find;
if (find_player(p, size, find) == (-1)) {
count << "No such player exists";
}
else {
print_player(p[find_player(p, size, find)]);
}

return 0;
}

void print_player(const Player &p) (//not important)

int find_player( Player p[ ], int size, string x) {
for (i=0, i < size, i++) {
if (p.name == x)
return i;
else
return (-1);
}
 
Last edited:
Physics news on Phys.org
On what line does the error occur?
 
The error occurs on the lines where i use the find_player function. I get two of them and they are both identical. Oh btw this is in g++
 
The signature of find_player is
find_player(Player , int , string)
But you said:
find_player(p, size, find)
Where find was an int.

retype "find" as a string.
 
I get the error "Conversion from Player* to non-scalar type Player requested
 
sorry that was me copying my program incorrectly.I can't seem to make emacs copy over to this text box. In my program it was actually a string sorry. I edited that so there is no more confusion.
 
Okay, well, also, your prototype and your declaration for find_player do not match. Contrast:
int find_player(Player , int , string);
With:
int find_player( Player p[ ], int size, string x) {

"Player" is a scalar, "Player[]" is a non-scalar.
 
Thank you that was the problem. That helped me out a lot.