Well, given the prototype "void GetLastName( Name lastName )", it seems reasonable to expect that the name will be copied into lastName. So, yes. Try it and see what happens.
Printable View
Well, given the prototype "void GetLastName( Name lastName )", it seems reasonable to expect that the name will be copied into lastName. So, yes. Try it and see what happens.
Well this seems like it works.
But I don't see the reason for a parameter in a getter.Code:void GetLastName(Name lastName)
{
strcpy(last,lastName);
}
This isn't really a getter function per se. It's more like a retrieval function or something. It's a getter but because of language syntax you have to pass in an argument and have that filled in, rather than returning the value. Same thing if you'd wanted to return two values: functions are only allowed to return one value so you might have to do
since "(int, int) getTwoValues()" isn't valid.Code:void getTwoValues(int &returnValue1, int &returnValue2) {
returnValue1 = 12;
returnValue2 = 55;
}
Like I said, you could write your particular getter without a parameter by returning a pointer instead, but if you're just learning about arrays now then the instructor might not have wanted to go into details about having to preserve the scope of the variable you're returning, etc.
Okay I think I understand it all now! Thanks for all the help I think I would have been stuck for a long time if you didn't help! We have learned arrays just he likes making things difficult for us that's all! :D