I've made a class called Player, whose goal is to create a new object player that has these attributes as below and vector of 5 strings (skills of player).
Player(string name, string surname, int height, vector<string> skills) {
this->name = name;
this->surname = surname;
this->height = height;
this->skills = skills;
}
I've also created a method that shows data of an object.
// Method showing data
string show_data() {
stringstream ss;
string s;
ss <<
this->name << " " <<
this->surname << " " <<
this->height << " ";
for (int i = 0; i < 5; i++) {
ss << this->skills[i] << " ";
}
ss << "\n";
s = ss.str();
return s;
}
My goal is to group 5 players into one team in another class. I've printed out the data of players
cout << "Liverpool\n" << p1.show_data() << p2.show_data() << p3.show_data() << p4.show_data() << p5.show_data() << endl
But I want to have something like
cout << liverpool.show_data(); and it should print the data of all 5 players
cout << real_madrit.show_data(); etc..
The question arises, how can I pass these 5 objects to another class with their attributes?
Teamclass that has astd::vector<Player>.Player) that groups 5 objects of a different class (std::string), then ask how to define a class that groups 5 objects of a different class. Where's the problem? Did you try it and run into a problem?