There are really only three options (in C++03, pre-C++11) to pass a parameter: by value, by reference or by const-reference. In the case of the copy-constructor, you cannot pass the parameter by value because to be able to do the copy (of the passed object), you need a copy-constructor, so that's impossible. The remaining options are by reference or const-reference, which I think you know already.
So, this boils down to the difference between a reference and a const-reference. As you said, a reference is a kind of const-pointer in disguise. However, like a pointer, it can refer to either a const or non-const object. So, what a const-reference really means is that you obtain a reference to an object that you are not allowed to modify, which is usually fine for a copy-constructor (i.e., a "copy" usually should not modify the original object). And as per the principle of minimum requirements, you should not require that the object be modifiable if you really don't need to modify it, and that is why you would almost always use a const-reference for the parameter of the copy-constructor (although, technically, you could use a non-const reference too, but you will have some rvalue/lvalue issues).
A const-reference is generally preferred whenever the object could be expensive to copy (or cannot be copied at all, like when it is a parameter to a copy-constructor) and all you really need is to be able to "look" at the object (read-only operations). Non-const references should only be used if you really want to modify the object that is passed to the function as a form of output of your function.
I suggest these FAQs as further reading on constness issues.
@mike:I just wanted to know being const pointer , what is the need to pass the const reference. i believe it should have passed without const . i have read so many places that reference is const pointer. Could you please through some light on this .
A reference is a constant pointer in the sense that the reference cant be changed to point to something else. You can still change the value that reference points to. On the other hand if you pass a const reference then you cant change the value that the reference holds.
i have read so many places that reference is const pointer.
Not so much. While it may help to think of references as constant pointers where indirection is done for you, eventually that relation will fall short. Here are a couple of notable differences:
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...