Copy Constructor

Hi all,
While using a copy constructor we are passing a const reference as parameter for the constructor. Why can't we use a pointer instead of reference?.

Does this sounds silly????


Regards
Edit: See Below
Last edited on
A pointer *can* guarantee the const-ness of the data pointed to:
int* const x;
is quite different from
const int* x;
While the former statement states that the value of the pointer cannot change (i.e., you cannot write x = &y), the latter states that the data pointed to cannot change (i.e., you cannot write *x = 5).

The standard defines copy-constructors as (12.8-2):
A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments

So, the answer to your question is: because it is defined this way in the standard.
the reason is because when you use a reference it´s become more easy to modify

Topic archived. No new replies allowed.