What is slicing?

View previous topic View next topic Go down

What is slicing?

Post  Admin on Sun Jan 31, 2010 5:45 pm

Answer:
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.

Database interview questions

Click here More information available

Admin
Admin

Posts : 71
Join date : 2010-01-21

View user profile http://campus-interview.co.cc

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum