Unknown errors while trying to use a show function for a class

Can someone help please this is due in 6 hours lol, i tried a new show function since maybe that was the problem, now i'm getting these 4 errors.
Lines 9-14 .
Help is very appreciated

||=== Build: Debug in Program3 (compiler: GNU GCC Compiler) ===|
C:\STAC CP2- brennan\prog3\Program3\main.cpp||In function 'void showGoalies(Goalie*, int)':|
C:\STAC CP2- brennan\prog3\Program3\main.cpp|129|error: invalid use of member 'std::__cxx11::string Goalie::getName() const' (did you forget the '&' ?)|
C:\STAC CP2- brennan\prog3\Program3\main.cpp|129|error: expected ')' before 'c_str'|
C:\STAC CP2- brennan\prog3\Program3\main.cpp|131|error: invalid use of member 'void Goalie::setName(const string&)' (did you forget the '&' ?)|
C:\STAC CP2- brennan\prog3\Program3\main.cpp|132|error: invalid use of member 'void Goalie::setTeam(const string&)' (did you forget the '&' ?)|
||=== Build failed: 4 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  void showGoalies(Goalie *g_ptr, int count)
{
    /* Display the headings for each column, with spacing and justification flags */
    printf("%s%15s%25s%8s\n", "Name", "Team", "Wins", "Losses");

    // Read goalie data from file using ',' as a delimiter.
    for (int i = 0; i < count; i++) {

        if (g_ptr->setName.c_str() != 0) {
            printf("%-8d%-30s%-10d%-2.2f\n",
                    g_ptr->setName.c_str(),
                    g_ptr->setTeam.c_str(),
                    g_ptr->setWins,
                    g_ptr->setLosses);

            g_ptr++;
        }
        /* If the name field is zero, then we reached the last player, break
         * out of the for loop.
         */
        else
            break;
    }

}
Last edited on
This is the other method i tried, but nothing is displaying on my run window, just a black window

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//show function
void showGoalies(Goalie *goalies, int count)
{
    cout << left;

    cout << setw(15) << "Name" << setw(10) << "Team" << setw(10) << "Wins" << setw(10) << "Losses" << setw(10) << "Goals Allowed" << setw(10) << "Shots Against" << endl;
    for(int i = 0; i < count; i++) {
        cout << setw(15) << goalies->getName();
        cout << setw(10) << goalies->getTeam();
        cout << setw(10) << goalies->getWins();
        cout << setw(10) << goalies->getLosses();
        cout << setw(10) << goalies->getGoalsAllowed();
        cout << setw(10) << goalies->getShotsAgainst();
        cout << endl;
        goalies++;
    }

    cout << setprecision(3) << (double)1796/1958 << endl;
}
1
2
3
4
5
6
        if (g_ptr->setName.c_str() != 0) {
            printf("%-8d%-30s%-10d%-2.2f\n",
                    g_ptr->setName.c_str(),
                    g_ptr->setTeam.c_str(),
                    g_ptr->setWins,
                    g_ptr->setLosses);


If those are all functions, you forgot all of the "()".

Also, "set...()" sounds like a function that modifies a value and returns nothing. In that case, you can't call .c_str() on the result. Did you mean g_ptr->get...()?

Edit: Also, what value is being passed to dount? If it's 0, the loop will never run.
Last edited on
Already asked in http://www.cplusplus.com/forum/beginner/274438/3/

Please don't have multiple threads for the same question. It ends up wasting people's time.
Topic archived. No new replies allowed.