mercredi 30 octobre 2019

How to unify the Scoreboard class to have Team classes as members?

I want to be able to declare statements in int main() like:

Scoreboard s1; //assuming T1 and T2 as public members

s1.T1.setName("Dallas Cowboys");
s1.T2.setName("Houston Texans");

Scoreboard s2; //assuming T1 and T2 as private members passed as parameters accessed with setters and getters

s2.Team1().setName("Dallas Cowboys"); 
s2.Team2().setName("Houston Texans"); 

That what I have in my main but it currently throws an error of:

  • No member named T1 in scoreboard
  • No member named T2 in scoreboard

The second error comes from the second Scoreboard and throws exactly the same error but with the difference that instead of using T1, T2. It uses Team1(), Team2(). I tried changing their names to T1 & T2 but still its not working :/.

My scoreboard class pretty much just looks like this but I just can not figure out my problem:

class Scoreboard{
  private:
    Team T1;
    Team T2;
  public:
    Scoreboard(){
      T1.setName(""); 
      T2.setName(""); 
    }
    // Setters
    void setTeam1(Team team1) { T1 = team1; }
    void setTeam2(Team team2) { T2 = team2; }

    // Getters
    Team getTeamOne() const { return T1; }
    Team getTeamTwo() const { return T2; }
    // Print current data stored at Student on demand
    void showScoreboard(){
      cout << "SCOREBOARD CURRENT DATA" << endl;
      cout << "Team1                          Visitor" << endl;
      cout << " " << T1 << "\t\t\t\t\t\t\t\t" << T2 << endl;
    }
};

Do you guys have any idea of where my error comes from?

Aucun commentaire:

Enregistrer un commentaire