in Programming in C
232 views
0 votes
0 votes
What is meant by object slicing?
in Programming in C
by
232 views

1 Answer

0 votes
0 votes

Object slicing  happens when a derived class object is assigned to a base class object, additional attributes of a derived class object are sliced off to form the base class object.

class Base { int x, y; };

class Derived : public Base { int z, w; };

int main()

{

    Derived d;

    Base b = d; // Object Slicing,  z and w of d are sliced off

}

http://www.geeksforgeeks.org/object-slicing-in-c/

edited by