if we do not writer our own assignment operator then which problem may occur?
Answers
Answer:
If we do not write our own assignment operator then which of the following problem may occur? Memory Leak Dangling pointer NULL pointer Unreferenced memory What functionality the following program is performing? read and write member functions of cin and cout objects are used to read a sentence from the keyboard and then print it on the screen.
Explanation:
Explanation:
- When we don't write our own assignment operator, the compiler generates a default assignment operator that performs a member-wise assignment.
- This means that if an object of a class has data members, then the default assignment operator will assign the values of the right-side object to the data members of the left-side object.
However, if the class has pointer members, the default assignment operator will only copy the memory addresses of the right-side object's pointer members to the left-side object.
This can lead to problems such as memory leaks and the double deletion of dynamically allocated objects. To avoid these problems, it is advisable to write a custom assignment operator that properly manages the memory associated with the pointer members.
Learn more about assignment operator
https://brainly.in/question/48025522
#SPJ3