Answer Posted / hemanth
Deep Copy and Shallow Copy
The terms "deep copy" and "shallow copy" refer to the way
objects are copied, for example, during the invocation of a
copy constructor or assignment operator. In a deep copy
(also called "memberwise copy"), the copy operation
respects object semantics. For example, copying an object
that has a member of type std::string ensures that the
corresponding std::string in the target object is copy-
constructed by the copy constructor of class std::string.
class A
{
string s;
};
A a;
A b;
a=b; //deep copy
When assigning b to a, the compiler-generated assignment
operator of class A first invokes the assignment operator
of class std::string. Thus, a.s and b.s are well-defined,
and they are probably not binary-identical. On the other
hand, a shallow copy (also called "bitwise copy") simply
copies chunks of memory from one location to another. A
memcpy() operation is an example of a shallow copy. Because
memcpy() does not respect object semantics, it will not
invoke the copy constructor of an object. Therefore, you
should never use memcpy() to copy objects. Use it only when
copying POD (Plain Old Data) types: ints, floating point
numbers, and dumb structs.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Can an interface inherit a class?
assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).
What are the types of abstraction?
What are the 3 pillars of oop?
What is encapsulation example?
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
Why is there no multiple inheritance?
What are oops methods?
why reinterpret cast is considered dangerous?
What is polymorphism used for?
write a program that takes input in digits and display the result in words from 1 to 1000
What does sksksk mean in text slang?
any one please tell me the purpose of operator overloading
What are the 4 main oop principles?
Which type does string inherit from?