References to structures.

I'm having a bit of trouble with a function that prints the entirety of a structure, but when attempting to tell the structure what the variables inside it mean, it comes up with an error, but here is the code:

1
2
3
4
5
6
7
8
9
void Make_Candy_Bar(CandyBar &CandyCake, const char * Name,const double Weight, const signed short Calories)
{
	CandyCake.name = *Name;
	CandyCake.weight = Weight;
	CandyCake.calories = Calories;


	cout << CandyCake.name  << ", " << CandyCake.weight << ", " << CandyCake.calories << ".\n";
}


I'm getting an error here:
CandyCake.name = *Name;

It's under the CandyCake.name; the error shown is this:
Error:expression must be a modifiable lvalue


If any more information is needed or you think you have a solution, please let me know.

Thanks,

Ben.
name is probably a char array instead of a std::string.
They are both char's.

That is

CandyBar.name (or CandyCake.name) is a char array
and Name is a char.
Last edited on
Yeah, you can't assign C arrays to each other.
Change both types to std::string.
Okay, thanks!
Topic archived. No new replies allowed.