Question

Why are we required to provide a copy constructor and a destructor in C++ when they...

Why are we required to provide a copy constructor and a destructor in C++ when they are not required in Java. Explain in detail.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

The copy constructor or destructor is a fundamental part of C++, since it automatically makes a local copy or destroys of an object. In Java everything that we manipulate is a handle, while in C++ you can have handle-like entities and you can also pass around the objects directly. That’s what the C++ copy constructor is for: when you want to take an object and pass it in by value, thus duplicating the object. So it works fine in C++, but you should keep in mind that this scheme fails in Java, so don’t use it.

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Why are we required to provide a copy constructor and a destructor in C++ when they...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT