473,324 Members | 2,370 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,324 software developers and data experts.

Copy constructor

Hi,

Can someone please explain what a copy constructor does and how it's
useful? Thanks,

Terry

Jul 19 '05 #1
4 3160
"Terry" <te***@nospam.com> wrote in message
news:3f********@clarion.carno.net.au...
Hi,

Can someone please explain what a copy constructor does and how it's
useful? Thanks,

It constructs an object (like the regular c'tor) from an already
existing object. This way you avoid first constructing and then assigning
(ie. two steps, instead of one).

hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #2
A

Hi,

Can someone please explain what a copy constructor does and how it's
useful? Thanks,

It constructs an object (like the regular c'tor) from an already
existing object. This way you avoid first constructing and then assigning
(ie. two steps, instead of one).


can't you use use the assignment operator to copy? that should be one step
as well.

asasas


Jul 19 '05 #3
"A" <A@iprimus.com.au> wrote...

Hi,

Can someone please explain what a copy constructor does and how it's
useful? Thanks,

It constructs an object (like the regular c'tor) from an already
existing object. This way you avoid first constructing and then assigning (ie. two steps, instead of one).


can't you use use the assignment operator to copy? that should be one step
as well.


No. Assignment operator is useless when passing parameters by
value or returning by value is concerned. Those are the main
uses of the copy constructor.

Victor
Jul 19 '05 #4

"A" <A@iprimus.com.au> wrote in message
news:3f********@news.iprimus.com.au...

Hi,

Can someone please explain what a copy constructor does and how it's
useful? Thanks,

It constructs an object (like the regular c'tor) from an already
existing object. This way you avoid first constructing and then assigning (ie. two steps, instead of one).


can't you use use the assignment operator to copy? that should be one step
as well.

asasas


A a;
A b(a); // copy construct, one step
A c; // default construct, step 1
c = a; // assign, step 2

Creating a copy of an object using assignment uses two steps, first the
object is constructed, then it is assigned.

john
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
8
by: Jesper | last post by:
Hi, Does the concept "copy constructor" from c++ excist in c#. What is the syntax. best regards Jesper.
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
8
by: shuisheng | last post by:
Dear All, I am wondering how the default copy constructor of a derived class looks like. Does it look like class B : public A { B(const B& right) : A(right) {}
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...
9
by: puzzlecracker | last post by:
From my understanding, if you declare any sort of constructors, (excluding copy ctor), the default will not be included by default. Is this correct? class Foo{ public: Foo(int); // no...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.