syntax of copy constructor

S

subrat

Hello,
I have adoubt on the signature of copy constructor.
Why one should always use const reference and not pointers as arguments?
I know why reference is used. But why cant I use pointers?

Thanks in advance.
Subrat@Bangalore
 
R

Rolf Magnus

subrat said:
Hello,
I have adoubt on the signature of copy constructor.
Why one should always use const reference and not pointers as arguments?

Because it wouldn't be a copy constructor then.
I know why reference is used. But why cant I use pointers?

You can. Then you get a conversion constructor from a pointer into an object
of your class.
 
V

Victor Bazarov

subrat said:
I have adoubt on the signature of copy constructor.
Why one should always use const reference and not pointers as
arguments? I know why reference is used. But why cant I use pointers?

Because then it's not a copy constructor by definition, but a parameterised
constructor from a pointer.

V
 
?

=?ISO-8859-15?Q?Stefan_N=E4we?=

subrat said:
Hello,
I have adoubt on the signature of copy constructor.
Why one should always use const reference and not pointers as arguments?
I know why reference is used. But why cant I use pointers?

A copy c'tor is by definition (i.e. _The Standard_) of the
form:

T(T&)
T(const T&)
T(const volatile T&)

Any other c'tor is not a copy-c'tor.

/S
 
G

Greg Comeau

I have adoubt on the signature of copy constructor.
Why one should always use const reference and not pointers as arguments?
I know why reference is used. But why cant I use pointers?

C++ requires that a copy ctor have a certain form, um,
as a convenience.

You can of course create your own ctors, so long as
they do not bump into any other rules.

I sense another underlying question in your question? :)
 
G

Greg Comeau

A copy c'tor is by definition (i.e. _The Standard_) of the
form:

T(T&)
T(const T&)
T(const volatile T&)

Any other c'tor is not a copy-c'tor.

volatile T& too.

It can also happen upon the other case where all the other arguments
after the T&'d one mentioned above are default'ed before such a call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top