Why a "operator=(...)" when there is a copy ctor?
Answers were Sorted based on User's Feedback
Answer / guest
You use the assignment operator (operator = ()) whenever an
existing object is to be replaced with a different object.
The copy constructor X(const X&) is used to create a new
instance of an X-object exactly like another.
Notice the subtle difference. Assignment changes an existing
object while construction creates a new object. You can view
assignment as the application of a destructor, to flush away
the existing object, followed by a copy construction, to
make an exact copy of the assigned object.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / arun
Copy Constructor means creation of new object and after that
copy properties of some exiting object to newly created object.
Overloading assignment operator is that copy properties of
some exiting object to another exiting object of same type.
| Is This Answer Correct ? | 1 Yes | 0 No |
Why multiple inheritance is not allowed?
write a c++ code to overload + and - for a stack class such that + provides push and - provides pop operation
1 Answers College School Exams Tests, HCL, IBM, TCS,
what is a class
What is overloading and its types?
What is difference between class and object with example?
What is virtual class and friend class?
write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.
What are different oops concepts?
what is the drawback of classical methods in oops?
What is oop in simple words?
write a program to find 2^n+1 ?
define oops with class and object