Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is deep and shalow copy?

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


Please Help Members By Posting Answers For Below Questions

How oops is better than procedural?

1030


What language is oop?

967


write a program to find 2 power of a 5digit number with out using big int and exponent ?

2326


What are oops functions?

965


What does I oop mean?

1023


What are the types of abstraction?

998


What is oops and its features?

1026


What is an example of genetic polymorphism?

1119


What are main features of oop?

1083


What does sksksk mean in text slang?

2055


What is overloading in oops?

1094


Why is polymorphism important in oop?

1012


What are the 5 oop principles?

1073


What is interface in oop?

1075


i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<

1812