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 7 6319
* 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?
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
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?
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?
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?
* 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?
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
by: MSR |
last post by:
I have a couple of questions.
1. Copy Constructor.
class A {
private:
int a1;
double d1;
char *ptr;
|
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...
|
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...
|
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...
| |
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...
|
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.
...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |