Differene between reference object and value object

This is a discussion on Differene between reference object and value object within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by csonx_p
Oh, now you making interesting comment to me here ... So in some regard, one can ...

Oh, now you making interesting comment to me here ... So in some regard, one can refer an address variable a const pointer to some degree! The differences between

Code:

Address& add;
const Address& myadd;

you can change the members of add class (setAddress(x, y, z), etc), but with myadd, you cant?? But, also you can't change add to another Address object....

That's right. (And of course, you can't change myadd to another address object either.) And since it's a reference, any changes made in this function are reflected back in the original wherever-we-came-from as well. (I think we're dealing with functions here, but I admit I've lost track.)

If we were using pointers, it would be Address * const add - that is, the pointer itself can not change, but the content can.

However, _I_ still think you should use a Address member, not a reference - there is no point in using a reference here - you still need an address, and the address itself is not a free-standing object that makes any sense. So storing the address in full inside the driver is a fine thing to do.

you can change the members of add class (setAddress(x, y, z), etc), but with myadd, you cant?? But, also you can't change add to another Address object....

Put in very simply terms... you can only call const functions on the myadd variable, because it's a const reference.
A const function is, simply put, a function that promises to never change the internal state of the class*.