object slicing in c++

C++
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 
}
# This can be prevented by using pointers.
Source

Also in C++: