1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Error: Conversion from scalar to nonscalar

  1. Nov 28, 2007 #1
    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;

    cout << endl; << "Please enter players name: "
    cin >> find;
    if (find_player(p, size, find) == (-1)) {
    cout << "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;
    return (-1);
    Last edited: Nov 28, 2007
  2. jcsd
  3. Nov 28, 2007 #2
    On what line does the error occur?
  4. Nov 28, 2007 #3
    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++
  5. Nov 28, 2007 #4
    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.
  6. Nov 28, 2007 #5
    I get the error "Conversion from Player* to non-scalar type Player requested
  7. Nov 28, 2007 #6
    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.
  8. Nov 28, 2007 #7
    Okay, well, also, your prototype and your declaration for find_player do not match. Contrast:
    int find_player(Player , int , string);
    int find_player( Player p[ ], int size, string x) {

    "Player" is a scalar, "Player[]" is a non-scalar.
  9. Nov 28, 2007 #8
    Thank you that was the problem. That helped me out alot.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?