Pages

Tuesday, May 7, 2013

What is object slicing?

When a derived class object is assigned to base class object, only base class properties copied to base class object and leave the derived class properties.This is called object slicing.

Ex:Class Base
{
 public: int i;
 }
 
 class Derived :Base
 {
 public : intj;
 }
 
 int main()
 {
    Base Bobj;
    Derived Dobj;
    Bobj=Dobj;//Here Dobj contains both i and j
    //But only i is copied to Bobj
 }

0 comments:

Post a Comment