Error: Conversion from scalar to nonscalar

  • Thread starter Thread starter VinceStolen
  • Start date Start date
  • Tags Tags
    Error Scalar
Click For Summary

Discussion Overview

The discussion revolves around a programming error encountered in C++ related to the conversion of types, specifically involving a function that searches for a player in an array of structures. The scope includes technical explanations and debugging assistance.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes a compiler error related to the function find_player, indicating confusion about the relevant code section.
  • Another participant asks for clarification on the specific line where the error occurs.
  • A participant points out a mismatch between the function signature and the way it is called, suggesting that the variable "find" should be a string rather than an int.
  • One participant reports receiving an error message about converting from Player* to a non-scalar type Player.
  • A participant acknowledges a mistake in copying the code and confirms that "find" is indeed a string in the actual program.
  • Another participant highlights the discrepancy between the function prototype and its declaration, noting that "Player" is a scalar type while "Player[]" is a non-scalar type.
  • Finally, one participant expresses gratitude for the assistance, indicating that the issue has been resolved.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the error and the necessary corrections, with some clarification needed on the function signature and variable types.

Contextual Notes

The discussion reveals potential limitations in understanding the distinction between scalar and non-scalar types in C++, as well as issues related to code copying and formatting that may have contributed to the confusion.

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:
Technology 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.
 

Similar threads

Replies
12
Views
3K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 15 ·
Replies
15
Views
4K
Replies
3
Views
1K
Replies
5
Views
2K
Replies
12
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K