Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

OOP help C++!!

OpenStudy (anonymous):

I've got a player class which looks like this: class player{ protected: string name; string pos; int quality; int aggression; ... public: player(string name,string pos,int quality,int aggression,...) { this->name=name; this->pos=pos; .... } } and a class team handling a group of players class team{ protected: vector<player> players; string nameteam; ... public: { team(string filename) { //read data from file } } }

OpenStudy (anonymous):

The problem is when I read data from file I can initialize the team class fields(teamname,formations,...) but I dont know how to initialize the player fields in the same constructor team();

OpenStudy (anonymous):

@inkyvoyd @imqwerty @Zarkon @mathmale @ParthKohli @rvc @nincompoop @Nnesha

OpenStudy (anonymous):

Make an object of Player in the main method. and then pass it to the constructor team. So the constructor looks like public team (Player p,string filename) { //p.field_name; .... } I hope this helps.

OpenStudy (anonymous):

@wiseyk think about that the file from where I read got 1 team and 25 players so I must use stl vector <player> but I dont know how it works.

OpenStudy (anonymous):

Tiny Guide to vectors 1.New std::vector<(type)> (name); 2.Append (name).push_back((Append This)); 4.Pop (name).pop_back() 3.Access (name)[(index)] 4.Interate for((type) (var):(vector name)) { ..... } Hope you find this useful Tux.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!