Can arrarys in a class store data from another class?

Hi guys,

I have set up a class where the user enters a team name and it will display that name and also the starting points for that team (starting points are 0)

The problem i'm having is, I want to create another class which acts as a manager class for the team class and I was wondering is it possible to set up an array in the manager class which can grab and contain data which is stored in the first class?

void set_team1_name (const string &),set_team2_name (const string &),set_team3_name (const string &),set_team4_name (const string &);
};

void cteams::set_team1_name (const string &team1)
{
f_team1 = team1;
}


class cleague
{




};

int main()
{
cteams teamscore (0);
cteams teams (0);

string team1;
string team2;
cout << "Enter Team 1 here: " << endl;
getline (cin, team1);



these are small snippets of the code. any help most appreciated thanks
You can create an array, a vector or whatever container with elements of the type of the 1st class as member of the second
eg:
1
2
3
4
5
6
7
8
9
10
class A
{
    public:
        A ( ); // notice: you must have a constructor which takes no arguments to create an array
};

class B
{
    A array[ nuber_of_elements ]; // notice: arrays have fixed size, while other containers can be resized
};
I'm still a little confused, could you possible elaborate a tiny bit more on this?

So say in my case I had

class cteams
{
public
void set_team1_name (const string &);
};

and in class cleague
{
set_team1_name [team1,team2,team3,team4];
};

would that work out correct? thanks for your help


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class cteams
{
   public:
      void set_team_name (const string &); // single team => no '1' in the function name
};

cleague
{
   private:
      cteams teams[4]; // declare array
   public:
      set_team1_name(const string &name)
      {
          teams[0].set_team_name ( name ); // call function for the 1st element of the array
      }

      // Do the same for the others, notice that the nth array element index is n-1
};
I'm a little confused with having a constructor taking no arguments?

when i run my code it asks me to enter team names which I do and then they get stored in the cteams class, ideally i would like to also store them in the cleague class as well.

And we meet again Bazzy, thanks so much for your help.
Excellent I'm with you now, thanks for your help buddy!!
right so instead of having void set_team1_name etc in class cteams I would have void set_team_name in class cteams and then void set_team1_name in the manager class?

why can i not keep set_team1_name in the original class?
Warning 2 warning C4183: 'set_team1_name': missing return type; assumed to be a member function returning 'int' c:\users\joe mcdermott\desktop\programing resit work\amateur football league\amateur football league\amateur football league.cpp 87 Amateur Football League


Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\joe mcdermott\desktop\programing resit work\amateur football league\amateur football league\amateur football league.cpp 85 Amateur Football League


these are the errors im getting? highly confused now LOL
Having set_team1_name in the class which represents just one team makes no sense.
The errors are there because I forgot 'void' before the function name in the example:
1
2
void set_team1_name(const string &name)
    // etc. 
Topic archived. No new replies allowed.