Functions & references.

Like what I did with the title there? I did.

Anyway, I'm having trouble with modifiable lvalues mixing with my structures:

1
2
3
4
5
6
7
void setgolf(golf & g, const char * name, int hc)
{
	g.handicap = hc;
	g.fullname = *name;


}


There's an error with this:
g.fullname = *name;

which is under the g and reads this:
Error: expression must be a modifiable lvalue

This is clearly to do with the const, but I have no idea as to how to rid of it.
Last edited on
Can you provide the golf class definition
Yup, here it is:
1
2
3
4
5
6
7
const int Len = 40;

struct golf
{
	char fullname[Len];
	int handicap;
};


(I know structs < classes, but I'm going by the book here (answering this error isn't the challenge, so it won't be ruined))

EDIT: Looking back, array problems are here, again, I haven't a clue as to how the errors will go.
Last edited on
Not a const problem at all.
You need to change the following line from
g.fullname = *name;
to
strncpy( g.fullname, name, Len - 1);


http://www.cplusplus.com/reference/clibrary/cstring/strncpy/
I know structs < classes

structs and classes are identical but for default privacy level.
Thank you, binary, it's a real help!
Topic archived. No new replies allowed.