Hi all, I got a question. Does anyone know that how to write a paragraph explaining the “ Big 3” - destructor, copy constructor and assignment operator?
Thanks in advance!
Hi all, I got a question. Does anyone know that how to write a paragraph explaining the “ Big 3” - destructor, copy constructor and assignment operator?
Thanks in advance!
Yes.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Yes. Start by opening a word processor. Then form complete sentences that support a main idea. Also, be sure to indent the first line.
Okay, here is why you have two answers that are rather unhelpful:
1. You asked a "does anyone know how to" kind of question, which merits a yes/no answer. Of course, people will often understand what you mean and cut out the "does anyone know" to interpret it as a "how to" question, which admittedly is your thread title. But...
2. You did not make any attempt to answer your own question, thus violating the homework policy.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I am not native English speaker. In my case, it is not easy to describe the big 3 well in English.
My answer is:
Copy constructor: when creating an object, the compiler calls the constructor automatically.
Destructor: automatically called by the compiler when an object archieve itsclosure.
Assignment operator: copy the right hand side into the left hand side.
I know my answer is not complete, any body can help me?
Write your full paragraph, and we'll tell you if we think something is incorrect or missing. Your start seems fine, but if you need to have a paragraph, then you should probably try writing a paragraph.
Copy constructor: when creating an object, the compiler calls the copy constructor automatically and make a copy of the default constructor.*1. When an object archieve itsclosure, the compiler called Destructor automatically to make the object exit.
Assignment operator copy the right hand side into the left hand side.
Above is my answer. For *1, I am not sure what will the copy constructor do before teh destructor is called. Any help?
>> I am not sure what will the copy constructor do before teh destructor is called.
What do you mean? The copy constructor, like any other constructor, just constructs the objects. The destructor will be called when that object is destroyed, regardless of which constructor was used to create it.