It is mentioned in C++ FAQ site -- \"larger derived class objects get sliced when passed by value as a base class object\", what does slicing mean? Any sample to demonstrate
Slicing means that the derived class information is lost. The base class parameter forces an object of the base class to created which share the same base-class state as the derived class. E.g:
struct B { int x; };
struct D : B { double y; };
void f(B b) {}
int main() {
D d;
f(d);
}
In the function f you will not be able to access D::y.
Edit: Thanks to everyone for editing. Please make sure that the edit adds value. Note that
structs the default inheritance is public.