What class can teamlist go in?

Hey guys, im getting an error with this code

Error 2 error C2228: left of '.set_team_name' must have class/struct/union c:\users\joe mcdermott\desktop\programing resit work\amateur football league\amateur football league\amateur football league.cpp 20 Amateur Football League


Here is the code:

class cteams
{
private:

public:

char teamlist[4];

void set_team_name(string &team_name)
{
teamlist[].set_team_name (team_name);
}



can anyone shed any light? thanks
EDIT:

oh wait.. that's a char. Nevermind what I wrote before.

You're trying to call "set_team_name" from your teamlist object, but teamlist is a char array, and char arrays do not have member functions. if "teamlist" is really meant to be the name of the team, you should:

1) rename it to it makes more sense. It's not a team list if it's the name of the team, then it's the team name. So change it to "name" or something else more suitable

2) make it a std::string. You still seem to be struggling with some very basic C++ concepts, so you shouldn't confuse yourself with the added difficulty of char arrays.

3) don't call 'set_team_name' on a char array or a string. If you have a string, just assign it:

1
2
3
4
5
6
7
8
9
10
class cteams
{
public:
  string  name;

  void set_team_name(string& team_name)
  {
    name = team_name;
  }
};


4) Please use code tags:

[code]
Paste your code in here
[/code]
Last edited on
What do you mean by putting an index in the bracket?
Sorry about that, ignore that. I didn't realize it was a char array -- I thought you were accessing an array of objects. Nevermind what I said before -- see my edit.
Topic archived. No new replies allowed.