Player player1("John Doe", 25, "Red"); string team = player1.GetTeam(); cout << "Player 1 belongs to the " << team << " team." << endl;
vectorIn this example, we create a vector of Player objects named "players". We then add three players to the vector, each with a name, age, and team. We use a for loop to iterate over each player in the vector, calling the GetTeam method to retrieve the team that each player belongs to, and outputting the results. Package library: This code example does not use any external package libraries.players; players.push_back(Player("Alice", 21, "Blue")); players.push_back(Player("Bob", 27, "Red")); players.push_back(Player("Charlie", 32, "Green")); for (auto player : players) { string team = player.GetTeam(); cout << player.GetName() << " belongs to the " << team << " team." << endl; }