473,227 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,227 software developers and data experts.

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 6287
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ccs | last post by:
In Meyers' book he gave an example of "virtual copy constructor", which is quite different to an "ordinary" copy constructor by: 1. it returns a pointer to an object instead of a reference. 2. it...
14
by: MSR | last post by:
I have a couple of questions. 1. Copy Constructor. class A { private: int a1; double d1; char *ptr;
5
by: Tony Johansson | last post by:
Hello! I'm reading in a book about C++ and that is something that sound strange. It says "Pointers have reference-assignment semantics similar to those in Java. For example, after the...
2
by: pragtideep | last post by:
Kindly help me explain the behaviour of defult copy constructor . Why the destructor is freeing the SAME memory twice , though it was allocated just once . #include<iostream> using namespace...
2
by: Jeremy Smith | last post by:
I am writing a program where speed is crucial, and one optimisation is that blocks of memory are re-used instead of being copied around and re- allocate. I have written my own vector-style class...
8
by: joel.winteregg | last post by:
Hi all, I "learnt" C++ a few years ago and then i have been using C for a couple of month and i'm now trying to get back to the ++ world (but with some troubles...). I have some problem to...
5
by: nagrik | last post by:
Hello group, Last week I picked up a thread, which pointed out that if a copy constructor is created with pointers instead of reference, there is a danger of it going in infinite recursion. ...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
4
by: Rahul | last post by:
Hi Everyone, It is well known that the input parameter which is passed to the copy constructor is passed as reference and not as as object. Because passing an object is as good as making another...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.