when we do not write our own assignment operator then which problem may occur?
Answers
Answer:
Run-Time Errors
Explanation:
When we don’t write our own assignment operator, compiler created assignment operator does shallow copy and those cause problems. In shallow copy, an object is created by simply copying the data of all variables of the original object. This works well if none of the variables of the object is defined in the heap section of memory. If some variables are dynamically allocated memory from the heap section, then copied object variable will also reference the same memory location.
This will create ambiguity and run-time errors dangling pointer. Since both objects will reference to the same memory location, then change made by one will reflect those change in another object as well. Since we wanted to create a replica of the object, this purpose will not be filled by Shallow copy.
Note: C++ compiler implicitly creates a copy constructor and overloads assignment operator in order to perform shallow copy at compile time.
Have a nice Day,
Adimali
Answer:
This is the best answer based on feedback and ratings. Memory Leak Dangling pointer NULL pointer Unreferenced memory
Explanation:
- This is the best answer based on feedback and ratings. Transcribed image text: 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.
- This is the best answer based on feedback and ratings. Transcribed image text: 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.
- When we don't provide an implementation of copy constructor (and assignment operator) and try to initialize an object with the already initialized object of the same class then copy constructor gets called and copies members of class one by one in the target object.
If we do not writer our own assignment operator then which problem may occur?
https://brainly.in/question/44471602
when we do not write our own assignment operator then which problem may occur?
https://brainly.in/question/44471156
#SPJ2