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:class Driver { public: Driver(); void SetDriverDetails(string fname, string lname, unsigned IDno, string contact, string license); string getFName(); string getSName(); Address getAddress(); string getContact(); unsigned getIDNo(); string getLicense(); ...
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.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?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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.
BTW i now have two SetAddress both with captal letter S... They are member functions to address and driver respectively...
here's the other one..
Code: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; }
But your get functions are lower-case, which made me think that ALL functions start with lowercase. Are you using the naming convention of "lowercase initial if it returns something, uppercase initial if it's a void function?" That would be fine, if that's the case. If it's "depending on how you felt like when you wrote that particular function", then you should make it more consistent. It appears that "setDateAndTime" is also lowercase initial - so I suspect most of your functions are just lowercase initial, and randomly, you decide to make some of them uppercase - that's definitely not a good plan.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.