Object slicing
Object slicing is a concept in C++ that occurs when an object of a derived class is assigned to an object of its base class. In this process, the portion of the derived class (i.e., the members and functionalities specific to the derived class) is "sliced off," leaving only the part of the base class. This happens because the base class object cannot hold the additional members and methods of the derived class. Why Does Object Slicing Occur? Object slicing occurs because of value assignment or passing objects by value . When a derived class object is copied into a base class object, only the base class part is copied. The derived class members, which extend the base class, are lost during this assignment. #include <iostream> using namespace std ; class Base { public: int baseVar ; virtual void show () { cout << "Base class variable: " << baseVar << endl ; } }; class Derived : ...