468,491 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Copy Constructor with Pointer instead of Reference

Hi,

What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}
Thanks & Regards,
Mohan
Oct 17 '06 #1
7 5810
* Mohan:
What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}
None of these are copy constructors.

Consult your nearest C++ textbook to learn what a copy constructor is.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 17 '06 #2

In case of copy constructor if we use donot use reference in that case
it will create an object and call the copy constructor and passing the
value to the copy constructor and each time a new object is created and
each time it will call the copy constructor it goes to infinite and
fill the memory then it display the error message .
if we pass the reference it will not create the new object for storing
the value. and no recursion will take place


Mohan wrote:
Hi,

What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}
Thanks & Regards,
Mohan
Oct 17 '06 #3
Thanks for the reply,

I am sorry, it was a copy/paste problem

Temp(const Temp *ptrBase)
{
}

My intention is to know will there be performace or any other issues ??

"Alf P. Steinbach" <al***@start.nowrote in message
news:4p************@individual.net...
>* Mohan:
What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}

None of these are copy constructors.

Consult your nearest C++ textbook to learn what a copy constructor is.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Oct 17 '06 #4
Thanks for the reply,

I am sorry, it was a copy/paste problem

Temp(const Temp *ptrBase)
{
}

My intention is to know will there be performace or any other issues in
using a Ponter instead of reference in Copy constructor??

"Alf P. Steinbach" <al***@start.nowrote in message
news:4p************@individual.net...
>* Mohan:
What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}

None of these are copy constructors.

Consult your nearest C++ textbook to learn what a copy constructor is.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Oct 17 '06 #5
Thanks for the reply,

I am sorry, it was a copy/paste problem

Temp(const Temp *ptrBase)
{
}

My intention is to know will there be performace or any other issues in
using a Ponter instead of reference in Copy constructor??

"Alf P. Steinbach" <al***@start.nowrote in message
news:4p************@individual.net...
>* Mohan:
What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}

None of these are copy constructors.

Consult your nearest C++ textbook to learn what a copy constructor is.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Oct 17 '06 #6
* Mohan:
Thanks for the reply,

I am sorry, it was a copy/paste problem

Temp(const Temp *ptrBase)
{
}

My intention is to know will there be performace or any other issues ??

"Alf P. Steinbach" <al***@start.nowrote in message
news:4p************@individual.net...
>* Mohan:
> What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?

For Example,

Writing the Copy constructor for the Class "Temp" as below,

Temp(const base *ptrBase)
{
}

instead of
Temp(const base &objBase)
{
}
None of these are copy constructors.

Consult your nearest C++ textbook to learn what a copy constructor is.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Please don't top-post. Please don't quote signatures. Please see my
original answer quoted somewhere above (it still applies, after the code
correction).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 17 '06 #7
"Mohan" <ra******@yahoo.comwrote in message news:eh**********@daniel-new.mch.sbs.de...
Thanks for the reply,

I am sorry, it was a copy/paste problem

Temp(const Temp *ptrBase)
{
}

My intention is to know will there be performace or any other issues ??
On performance, it's up to the machine and the compiler, but very likely there would be no
difference at all. On other issues, a reference would be more convenient than a pointer in most
cases, and absolutely essential in others, since your pointer version is not a copy constructor.
Whether to copy from a pointer or a reference just isn't an issue. AFAIK, everyone uses a reference
without even thinking.

DW
Oct 17 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by ccs | last post: by
14 posts views Thread by MSR | last post: by
5 posts views Thread by Tony Johansson | last post: by
2 posts views Thread by pragtideep | last post: by
8 posts views Thread by joel.winteregg | last post: by
4 posts views Thread by Rahul | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.