access a class that is a private member of another class

Hi, here my program I have a class wrestler and a class team. The class wrestler as you can see has ability point and weight etc...
The class team has wrestlers and points.
This program creates 20 different teams with a random number of wrestlers with a random ability and random weight.

What I'm trying to do is to access to the wrestlers that are part of team 1.

Here my .cpp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include <iostream>
#include <string>
#include <list>
#include <ctime>
#include <random>
using namespace std;
#include "classcreator.h"


int main()
{

    default_random_engine gen(time(NULL));
    uniform_real_distribution<double> teamn(10,18);
    normal_distribution <double> weightn(155,40);  ///138,70
    normal_distribution <double> abilityn(100,15);


    team TEAMs [20];
    int  numteam;
    int  idstarter = 1000;
    int  weight;
    int  ability;

    for(int i=1; i<6; i++)
            {

                numteam = teamn(gen);
                if ((numteam >= 10) && (numteam <= 18)){

                TEAMs[i].setpl(numteam);

                TEAMs[i].display(i);

                    for (int x=1; x<(numteam+1) ; x++){

                        wrestler w [numteam];
                        weight = weightn(gen);    ///normal distribution for number of players
                        ability = abilityn(gen);

                        w[x].setid(idstarter+x);

                        if ((weight >= 93) && (weight <= 285)){

                        w[x].setweight(weight);
                        w[x].setability(ability);
                        w[x].display();

                }else{
                x--;
                }
                }
                cout<<endl<<endl;
                idstarter=idstarter+1000;

                }else{
                i--;
                }
            }    ///error is here 

       if ( TEAMs[1].w[1].ability > TEAMs[2].w[1].ability){ cout <<"yeah"<<endl;}
       else { cout << "nooo" <<endl;}

    return 0;
}



I'm having the error over there in that if conditon

Here my .h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  class wrestler{

public:
    wrestler(){}
    ~wrestler(){}

    void setid(int i){id = i;}
    int getid(){return id;}

    void setweight(int w){weight = w;}
    int getweight(){return weight;}

    void setability(int a){ability = a;}
    int getability(){return ability;}

    void display(){cout<<"Player number "<<id<<" weights "<<weight<<" and it has an ability score of "<<ability<<endl;}

    friend class team;


private:
    int id;
    int weight;
    int ability;
    int weightclass;
    int wins;
    int losses;

};

class team{

public:
        team (){}
        ~team (){}

        void setpl(int p){players = p;}
        int getpl(){return players;}

        void setp(int o){points = o;}
        int getp(){return points;}

        void display(int g){cout<<"There are "<<players<<" players in the Team number "<<g<<endl<<endl;}

        friend class wrestler;


private:

    int points;
    int players;
    wrestler w [];  ///how do i access it
};


I understand that the ability and weight are private but I can't understand how to access them.

Thanks
You can only access private members in the team file. You can make a function in your team file that has access to wrestler w[]; and make a function call to the function in main.
@personxd1
Is there any chance that you can make a simple code example.
Please, that would be really appreciated.

Topic archived. No new replies allowed.