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

What is the difference between #define debug 0 and #undef debug?

0 Answers  


why we cant create array of refrences

4 Answers  


Will rust take over c++?

0 Answers  


Show the declaration for a static member variable.

0 Answers  


Why is null pointer used?

0 Answers  






What flag means?

0 Answers  


Define pre-condition and post-condition to a member function in c++?

0 Answers  


What is meant by iomanip in c++?

0 Answers  


What are register variables?

0 Answers  


What is the basic difference between C and C++?

0 Answers   NIIT,


Difference between class and structure.

0 Answers  


What is c++ stringstream?

0 Answers  


Categories