IT Community - Software Programming, Web Development and Technical Support

Copy constructor and an overloaded assignment operator

This is a discussion on Copy constructor and an overloaded assignment operator within the C and C++ Programming forums, part of the Software Development category; Copy constructor and an overloaded assignment operator A copy constructor constructs a new object by using the content of the ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-21-2007, 03:37 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Copy constructor and an overloaded assignment operator

Copy constructor and an overloaded assignment operator

A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.
First, the applicant must know that a copy constructor is one that has only one argument of the same type as the constructor. The compiler invokes a copy constructor wherever it needs to make a copy of the object, for example to pass an argument by value. If you do not provide a copy constructor, the compiler creates a member- by-member copy constructor for you.
You can write overloaded assignment operators that take arguments of other classes, but that behavior is usually implemented with implicit conversion constructors. If you do not provide an overloaded assignment operator for the class, the compiler creates a default member- by-member assignment operator.
This discussion is a good place to get into why classes need copy constructors and overloaded assignment operators. If the applicant discusses these with respect to data member pointers that point to dynamically allocated resources, the applicant probably has a good grasp of the problem.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion constructor vijayanand C and C++ Programming 0 09-21-2007 03:36 AM
sizeof() operator vigneshgets C and C++ Programming 2 09-11-2007 05:10 AM
Diffrence between a "assignment operator" and a "copy constructor" Sabari C and C++ Programming 1 07-24-2007 05:00 AM
Difference between a "assignment operator" and a "copy constructor"? vigneshgets C and C++ Programming 2 07-12-2007 05:30 AM
string copy (strcpy) and a memory copy (memcpy) vigneshgets C and C++ Programming 1 05-30-2007 11:40 AM


All times are GMT -7. The time now is 08:57 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0