What is slicing?



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

Post New Answer

More C++ General Interview Questions

If horse and bird inherit virtual public from animal, do their constructors initialize the animal constructor? If pegasus inherits from both horse and bird, how does it initialize animal’s constructor?

0 Answers  


How does com provide language transparency?

0 Answers  


What are single and multiple inheritances in c++?

0 Answers  


When do we use copy constructors?

0 Answers  


What is the size of integer variable?

0 Answers  






How is objective c different from c++?

0 Answers  


Are strings immutable in c++?

0 Answers  


What are the advantage of using register variables?

0 Answers  


What is class syntax c++?

0 Answers  


How Virtual functions call up is maintained?

2 Answers  


How const int *ourpointer differs from int const *ourpointer?

0 Answers  


Given the following function definition: int doit(int &x, int y, int &z) { x = 3*x; y = y + 5; z = x+y; return z - 4; } int a = 5, b = 7, c = 9, d = 11; d = doit(a,b,c);

2 Answers  


Categories