If You have a base class A
and a derived class B
, then You can do the following.
void wantAnA(A myA)
{
// work with myA
}
B derived;
// work with the object "derived"
wantAnA(derived);
Now the method wantAnA
needs a copy of derived
. However, the object derived
cannot be copied completely, as the class B
could invent additional member variables which are not in its base class A
.
Therefore, to call wantAnA
, the compiler will "slice off" all additional members of the derived class. The result might be an object you did not want to create, because
A
-object (all special behaviour of the class B
is lost).