What is slicing?
Answer / atul shankhwar
Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object.
Explanation:
Consider the following class declaration:
class base
{
...
base& operator =(const base&);
base (const base&);
}
void fun( )
{
base e=m;
e=m;
}
As base copy functions don't know anything about the derived only the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.
| Is This Answer Correct ? | 0 Yes | 0 No |
Can you please explain the difference between static and dynamic binding of functions?
What is realloc() and free()? What is difference between them?
What are Binay tress and B trees? Diff between them?
What is the type of 'this' pointer?
How can we access protected and private members of a class?
How does a C++ structure differ from a C++ class?
Why c++ is so important?
Will c++ be replaced?
If dog is a friend of boy and boy is a friend of house, is dog a friend of house?
make a middle node of doubly linklist to the top of the list
Describe friend function & its advantages.
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop