Answer Posted / 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 |
Post New Answer View All Answers
Give example of a pure virtual function in c++?
What are the extraction and insertion operators in c++?
What is the difference between structure and class?
Explain the difference between overloading and overriding?
What is polymorphism & list its types in c++?
Write bites in Turbo c++ Header ("Include") Files.
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What is an iterator class in c++?
What is an inclusion guard?
What is enum class in c++?
How do you sort a sort function in c++ to sort in descending order?
Write a program to find the Factorial of a number
Which bit wise operator is suitable for putting on a particular bit in a number?
Difference between inline functions and macros?
What are the important differences between c++ and java?