Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Assignment Operator - What is the diffrence between a "assignment operator" and a "copy constructor"?
Assignment Operator - What is the diffrence between a "assignment operator" and a "copy constructor"?
✍: Guest
Answer1.
In assignment operator, you are assigning a value to an existing object. But in copy constructor, you are creating a new object and then assigning a value to that object. For example:
complex c1,c2; c1=c2; //this is assignment complex c3=c2; //copy constructor
Answer2.
A copy constructor is used to initialize a newly declared variable from an existing variable. This makes a deep copy like assignment, but it is somewhat simpler:
There is no need to test to see if it is being initialized from itself.
There is no need to clean up (eg, delete) an existing value (there is none).
A reference to itself is not returned.
2012-03-30, 2766👍, 0💬
Popular Posts:
Can you tell me how to check whether a linked list is circular? Create two pointers, and set both to...
What would you use to compare two String variables - the operator == or the method equals()? You can...
What Is the Data Pump Import Utility? - Oracle DBA FAQ - Loading and Exporting Data Oracle Data Pump...
What does XmlValidatingReader class do? XmlTextReader class does not validate the contents of an XML...
What is more advisable to create a thread, by implementing a Runnable interface or by extending Thre...