I have created a class called cteams and when the program runs it asks the user to enter team names which are then stored in cteams.
What I want to do is create a manager class called cleague which will have a way of storing a collection of teams, these teams I want to come from the first class cteams.
Is this possible?here is some snippets of code which I have been working on trying to do this. thanks guys
#include <iostream>
#include <string>
using namespace std;
I want to set up an array in cleague which will hold the information from cteams if your with me? and I assumed that I would have to inherit the information from cteams in order to place it in to an array?
To access member variables/functions, you use the . operator (if you have an object) or the -> operator (if you have a pointer).
Here we have the normal object, so we'd use the . operator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class cleague
{
public:
void SomeFunction()
{
// teamlist[0].GetScore() calls the GetScore() function in the cteams class
// using 'teamlist[0]' as the object
if( teamlist[0].GetScore() > 100 )
{
// do something
}
}
protected:
cteams teamlist[ Number_of_teams ];
};
The problem im having here, is I want it to return a string and I'm not sure how to go about it? All I want is for it to put the team names which the user enters in to cteams and then for cleague to put them in to an array. I have managed to get them to store the names in cteams but still having megga problems with getting cleague to take them and put them in an array. However I do know that the "has a" relationship is deffo on the right tracks!!