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".

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?

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.

Don't forget the reference.
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.

07-16-2008

csonx_p

Quote:

Originally Posted by matsp

Where is setAddress?

Hangon, it is a member function of Address class. If Driver has an object of address, why can't i just use that setAddress from Address class?

07-16-2008

csonx_p

Quote:

Originally Posted by matsp

I expect you need to be able to "set" the address of a driver as well?

Code:

void Driver::SetAddress(Address add)
{
address = add;
}

just added....

07-16-2008

matsp

Quote:

Originally Posted by csonx_p

Code:

void Driver::SetAddress(Address add)
{
address = add;
}

just added....

I suppose that SHOULD be Driver::setAddress, rather than Driver::SetAddress? Just to be consistant.

--
Mats

07-16-2008

csonx_p

Quote:

Originally Posted by matsp

I suppose that SHOULD be Driver::setAddress, rather than Driver::SetAddress? Just to be consistant.

--
Mats

BTW i now have two SetAddress both with captal letter S... They are member functions to address and driver respectively...

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

07-16-2008

csonx_p

Quote:

Originally Posted by matsp

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.

Elysia's guilty as charged... He's the one who suggested this, and YES is the answer....

07-16-2008

matsp

Quote:

Originally Posted by csonx_p

Elysia's guilty as charged... He's the one who suggested this, and YES is the answer....

Techically, that would be "SHE suggested". That's fine, as long as it's consistent.