When a derived class object is assigned to a base class, only the base class's part of content in the derived object are copied to the base class, leaving behind the derived class specific contents. This is referred as Object Slicing.
Example:
Class Base
{
public int i;
};
class Derived : public Base
{
public int j;
};
int main()
{
Base objB;
Derived objD;
objB = objD;
//Here objD contains both i and j.
//But only i is copied to objB.
}
No comments:
Post a Comment