Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6708285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:44:27+00:00 2026-05-26T07:44:27+00:00

I’m running in to an issue with two classes that I created. It’s a

  • 0

I’m running in to an issue with two classes that I created. It’s a simple sports season program. I created one class called Season which is creating a vector of pointers to Game objects. The compiler is complaining about Game being an undeclared identifier even though I have the class defined and tested that it worked.

How come the Game class can not be used in the Season class or how can I get them to be used (maybe nest it in the public part of Season don’t know if that would be good or bad)?

class Season
{
public:
    Season();
    void add_game(int number, string a, int a_score, string b, int b_score);

private:
    vector<Game*> games;
    int game_high_score;
    string game_high_score_team;
    int season_high_score;
    string season_high_score_team;
    string champion;
};

Season::Season()
{
    int game_high_score = -2;
    string game_high_score_team = "Unknown";
    int season_high_score = -2;
    string season_high_score_team = "Unknown";
    string champion = "Unknown";
}

void Season::add_game(int number, string a, int a_score, string b, int b_score)
{
    Game* temp_game = new Game(number, a, b, a_score, b_score);
    games.push_back(temp_game);
}

string Season::toStr() const
{
    stringstream out;

    out << "Number of games in the season: " << games.size() << endl
        << "game_high_score_team: " << game_high_score_team
        << "\tScore: " << game_high_score_team << endl
        << "season_high_score: " << season_high_score
        << "\tScore: " << season_high_score << endl
        << "champion: " << champion << endl;

    return out.str();
}

// Game class stores values and has functions for each game of the season
class Game
{
public:
    Game();
    Game(int number, string a, string b, int a_score, int b_score);
    string winner(string a, string b, int a_score, int b_score);
    string toStr() const;
    string get_team_a() const;
    string get_team_b() const;
    int get_team_a_score() const;
    int get_team_b_score() const;
    string get_winner() const;
    int get_top_score() const;

private:
    int game;
    string team_a;
    string team_b;
    int team_a_score;
    int team_b_score;
    string won;
    int top_score;
};

Game::Game()
{
    game = -1;
    team_a = "";
    team_b = "";
    team_a_score = -1;
    team_b_score = -1;
    won = "";
    top_score = -1;
}

Game::Game(int number, string a, string b, int a_score, int b_score)
{
    game = number;
    team_a = a;
    team_b = b;
    team_a_score = a_score;
    team_b_score = b_score;
    won =  winner(team_a, team_b, team_a_score, team_b_score);
}

string Game::winner(string a, string b, int a_score, int b_score)
{
    if (a_score > b_score)
    {
        top_score = a_score;
        return a;
    }
    else if (a_score < b_score)
    {
        top_score = b_score;
        return b;
    }
    else
    {
        top_score = a_score;
        return "Tie";
    }
}

string Game::toStr() const
{
    stringstream out;

    out << "Game #" << game << endl
        << "team_a: " << team_a << "\tScore: " << team_a_score << endl
        << "team_b: " << team_b << "\tScore: " << team_b_score << endl
        << "Won: " << won << "\t TopScore: " << top_score << endl;
    return out.str();
}

int main(int argc, char* argv[])
{
    string file_name;
    Season sport;
    file_name = "season.txt"

    ifstream fin(file_name);
    if (fin.fail())
    {
        cout << "Could not read file: " << file_name << endl;
    }

    if (fin.is_open())
    {
        string temp;
        getline(fin, temp);

        int game;
        string a;
        string b;
        int a_score;
        int b_score;
        while (!fin.eof())
        {
            fin >> game >> a >> a_score >> b >> b_score;
            sport.add_game(game, a, b, a_score, b_score);
        }

        // close the input stream from the file.
        fin.close();
    }

    system("pause");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:44:27+00:00Added an answer on May 26, 2026 at 7:44 am

    The compiler reads your program line-by-line, starting at the beginning. At the point where you first reference Game:

    vector<Game*> games
    

    you have not yet declared Game.

    You must either move your Game declaration prior to Season, or you must forward-declare Game.

    To forward-declare Game, add this declaration prior to the definition of Session:

    class Game;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.