References to structures.
Oct 23, 2011 at 3:16pm UTC
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.
Oct 23, 2011 at 3:46pm UTC
name is probably a char array instead of a std::string.
Oct 23, 2011 at 3:50pm UTC
They are both char's.
That is
CandyBar.name (or CandyCake.name) is a char array
and Name is a char.
Last edited on Oct 23, 2011 at 3:51pm UTC
Oct 23, 2011 at 3:53pm UTC
Yeah, you can't assign C arrays to each other.
Change both types to std::string.
Oct 23, 2011 at 4:01pm UTC
Okay, thanks!
Topic archived. No new replies allowed.