Answer Posted / rajk
A shallow copy of an object copies all of the member field
values. This works well if the fields are values, but may
not be what you want for fields that point to dynamically
allocated memory. The pointer will be copied. but the
memory it points to will not be copied -- the field in both
the original object and the copy will then point to the
same dynamically allocated memory, which is not usually
what you want. The default copy constructor and assignment
operator make shallow copies.
A deep copy copies all fields, and makes copies of
dynamically allocated memory pointed to by the fields. To
make a deep copy, you must write a copy constructor and
overload the assignment operator.
Deep copy needs,
If an object has pointers to dynamically allocated memory,
and the dynamically allocated memory needs to be copied
when the original object is copied, then a deep copy is
required.
A class that requires deep copies will generally need:
i )a destructor to delete the dynamically allocated memory.
ii) a copy constructor to make a copy of the dynamically
allocated memory.
iii) an overloaded assignment operator to make a copy of
the dynamically allocated memory.
| Is This Answer Correct ? | 20 Yes | 0 No |
Post New Answer View All Answers
write string class as your own class in java without using any built-in function
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is overloading in oops?
Can we define a class within the interface?
What is static in oop?
Explain virtual inheritance?
Plese get me a perfect C++ program for railway/airway reservation with all details.
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
How to improve object oriented design skills?
What is constructor in oop?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation
There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.
What is data binding in oops?