473,763 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

initialization and assignment.

What is the difference between copy initialization and assignment.

How the memory will allocates the objects.

Thanks &regards,
Sai Kishore

Mar 5 '06 #1
7 3733

sk*******@yahoo .co.in wrote:
What is the difference between copy initialization and assignment.
Assignment changes the value of an existing object. Initialisation
creates a new object. They are fundamentally different things.
Copy-initialisation is one type of initialisation which creates a new
object as a copy of an existing object. Where are you learning C++? In
a class? From a book? Has this not been explained?
How the memory will allocates the objects.


If you understand the answer to the first question, the answer to this
question should be clear. But it might not be, so ask for clarification
of anything you still don't understand.

Gavin Deane

Mar 5 '06 #2

<sk*******@yaho o.co.in> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
| What is the difference between copy initialization and assignment.
|
| How the memory will allocates the objects.
|
| Thanks &regards,
| Sai Kishore
|

Assignment implies a brand new object or a target for modification: an
l-value.
A copy is a clone constructor. Sometimes not an identical clone.

Mar 5 '06 #3

Peter_Julian wrote:
<sk*******@yaho o.co.in> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
| What is the difference between copy initialization and assignment.
|
| How the memory will allocates the objects.
|
| Thanks &regards,
| Sai Kishore
|

Assignment implies a brand new object or a target for modification: an
l-value.


Assignment is when the value of an existing object is overwritten with
a new value. How does that imply a brand new object?

Gavin Deane

Mar 5 '06 #4
Hi Gavin,
I am asking that , Is it same memory allocation is used
for assignment operatot?
In copy initialization Is it different memory allcation.
Suppose if you take two objects , these two objects will use same
memory allcation or different memory allocation in assignment and copy
initialization.

Mar 7 '06 #5

"Gavin Deane" <de*********@ho tmail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
|
| Peter_Julian wrote:
| > <sk*******@yaho o.co.in> wrote in message
| > news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
| > | What is the difference between copy initialization and assignment.
| > |
| > | How the memory will allocates the objects.
| > |
| > | Thanks &regards,
| > | Sai Kishore
| > |
| >
| > Assignment implies a brand new object or a target for modification: an
| > l-value.
|
| Assignment is when the value of an existing object is overwritten with
| a new value. How does that imply a brand new object?
|
| Gavin Deane
|

read again, i didn't need to overload operator| here.

Mar 7 '06 #6

Peter_Julian wrote:
"Gavin Deane" <de*********@ho tmail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
|
| Peter_Julian wrote:
| > Assignment implies a brand new object or a target for modification: an
| > l-value.
|
| Assignment is when the value of an existing object is overwritten with
| a new value. How does that imply a brand new object?
|
| Gavin Deane
|

read again, i didn't need to overload operator| here.


Nope. I don't get it. Sorry. Can you clarify where a brand new object
might participate in assignment? A brand new object can't be the target
of assignment.

Gavin Deane

Mar 7 '06 #7
Please quote some relevant context from the message you are replying
to. From Google Groups, don't use the "Reply" link at the bottom of the
message. Click on "Show Options" at the top of the message and use the
"Reply" link that reveals.

sk*******@yahoo .co.in wrote:
Hi Gavin,
I am asking that , Is it same memory allocation is used
for assignment operatot?
As I said before, assignment changes the value of an existing object.
There is not necessarily any memory allocation at all.

There will be memory allocation *if* you are assigning to an object of
a type with a user-defined assignment operator *and* that assignment
operator allocates some memory. Are you considering assignment of such
a type? Or are you considering assignment as a concept in general?
In copy initialization Is it different memory allcation.
With any form of initialisation, including but not limited to
copy-initialisation, a new object is being created, so at the very
least some memory will be allocated for that object. In addition, for
copy-initialisation, there will be further memory allocation *if* you
are creating an object of a type with a user-defined copy constructor
*and* that copy constructor allocates some memory.
Suppose if you take two objects , these two objects will use same
memory allcation or different memory allocation in assignment and copy
initialization.


I don't understand that. It might help if you showed some code as an
example of the situation you are asking about. If you do that, make
sure you follow the guidelines in the FAQ for posting code otherwise it
won't help at all.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Gavin Deane

Mar 7 '06 #8

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

Similar topics

5
303
by: john sun | last post by:
Hi, I have a class with copy ctor and assignment operator. MyClasss obj1(data); MyClass obj2=obj1; in this case, the copy constructor is invoked instead of assignment operator. I cannot understand why? Thanks, John
50
3831
by: Charles Stapleton | last post by:
Given the folowing class class Ctest{ public: Ctest( int i, int j) :a(i) { b = j; } private: int a, b; } When creating an object of type Ctest, what advantage is there to setting
17
2080
by: Thomas Lorenz | last post by:
Hello, I'm a little confused about object initialization. According to Stroustrup (The C++ Programming Language, Special Edition, Section 10.2.3) constructor arguments should be supplied in one of the following notations: MyClass instance1 = MyClass(1, 2, 3); MyClass instance2(4, 5, 6); What's curious: the second notation variant is called an "abbreviated form"
2
1625
by: Matthias Kaeppler | last post by:
Hi, say I have an arbitrary class Bar: 1 Bar a; 2 Bar b(a); 3 Bar c = a; In line 3, is the default ctor called for c _first_ and _then_ the assignment operator, or is c never default constructed and immediately
6
13385
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
8
3122
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are initialized before the program starts executing." -- What does this mean? What is the name of the stage in which the mentioned initialization is performed? Compile-time or run-time? In the following snippet, variables b and c are defined at line 7...
11
2441
by: asdf | last post by:
The oder of member initialization is the order in which the members are defined. So the following code is problematic: class X{ int i; int j; public: X(int val):j(val),i(j){}
23
3661
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for the built-in types, the value is usually garbage. Is this right? However, I'm a bit confused about value-initialization, when does it happen, and what kind of values are assigned to objects?
2
2381
by: timlyee | last post by:
int *p = new int; auto_ptr<intap1 = p; //will fail on 3 1 auto_ptr<intap1(p); //ok 2 *ap1 = 12; // 3 the first situation has called : explicit auto_ptr(_Ty *_Ptr = 0) _THROW0() the second : auto_ptr(auto_ptr_ref<_Ty_Right) _THROW0()
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2794
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.