Object slicing

In C++ programming, object slicing occurs when an object of a subclass type is copied to an object of superclass type: the superclass copy will not have any of the member variables or member functions defined in the subclass.

This issue is not inherently unique to C++, but it does not occur naturally in most other object-oriented languages — not even in C++'s relatives such as D, Java, and C# — because copying of objects is not a basic operation in those languages.

Instead, those languages prefer to manipulate objects via implicit references, such that only copying the reference is a basic operation.

Additionally, due to the lack of garbage collection in C++, programs will frequently copy an object whenever the ownership and lifetime of a single shared object would be unclear.

For example, inserting an object into a standard library collection (such as a std::vector) typically involves making and inserting a copy into the collection.