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?
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
};
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.
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: