const string& firstLine
And the same for the rest.
Where is setAddress? I guess you just forgot it, but I didn't know you'd thought of it and forgot it, rather than just missed it out because of a "thinko".Code:
void SetDriverDetails(string fname, string lname, unsigned IDno,
string contact, string license);
The const reference , in for example the SetDriverDetails parameter list, would just tell the compiler "I just need the string of first name to read from, I'm not changing it, I promise", which means that the compiler doesn't have to COPY the string before passing it to the SetDriverDetails function. It also makes it easier to see that firstname ISN'T being changed by SetDriverDetails when viewing an overview of the code.Quote:
If you declare a variable const without initializing it, how does the compiler allow you to initialize it later, or is this an exception with the setters?
Better, but you should make them references too, e.g.. That is what really lets the compiler pass the address instead of a copy of the string.Code:
const string &fline
Don't forget the reference.Code:
void Address::setAddress(const string& fline, const string& sline, const string& sbb,
const string& city, const string& code)
Passing by reference means the original object is passed (typically its address). Otherwise the entire object needs to be duplicated which is slow.
By appending const you're telling the compiler you won't change it. Because it's a reference, the changes will reflect the original object and that's not good. You can stop that by adding const.
When passing by value, it hardly matters, because the original variable won't be affected anyway.
here's the other one..
void Address::SetAddress(const string& fline, const string& sline, const string& sbb,
const string& cty, const string& cde)
firstLine = fline;
secondLine = sline;
surbub = sbb;
city = cty;
code = cde;