Object slicing (original) (raw)

About DBpedia

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 defined in the subclass. These variables have, in effect, been "sliced off". More subtly, object slicing can likewise occur when an object of a subclass type is copied to an object of the same type by the superclass's assignment operator, in which case some of the target object's member variables will retain their original values instead of getting copied over from the source object.

Property Value
dbo:abstract 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 defined in the subclass. These variables have, in effect, been "sliced off". More subtly, object slicing can likewise occur when an object of a subclass type is copied to an object of the same type by the superclass's assignment operator, in which case some of the target object's member variables will retain their original values instead of getting copied over from the source object. 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. In C++, by contrast, objects are copied automatically whenever a function takes an object argument by value or returns an object by value. 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) actually involves making and inserting a copy into the collection. (en)
dbo:wikiPageExternalLink https://www.learncpp.com/cpp-tutorial/121-pointers-and-references-to-the-base-class-of-derived-objects/ https://www.geeksforgeeks.org/object-slicing-in-c/ https://stackoverflow.com/questions/274626/what-is-the-slicing-problem-in-c
dbo:wikiPageID 197995 (xsd:integer)
dbo:wikiPageLength 2987 (xsd:nonNegativeInteger)
dbo:wikiPageRevisionID 1098748229 (xsd:integer)
dbo:wikiPageWikiLink dbr:Member_variable dbr:Object-oriented_programming dbr:C++ dbr:C_Sharp_(programming_language) dbr:D_(programming_language) dbr:Garbage_collection_(computing) dbr:Java_(programming_language) dbc:C++ dbc:Object-oriented_programming dbc:Articles_with_example_C++_code dbr:Assignment_operator dbr:Diamond_problem dbr:Subtyping
dbp:wikiPageUsesTemplate dbt:About dbt:Mono dbt:Unreferenced dbt:C++_programming_language
dcterms:subject dbc:C++ dbc:Object-oriented_programming dbc:Articles_with_example_C++_code
rdfs:comment 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 defined in the subclass. These variables have, in effect, been "sliced off". More subtly, object slicing can likewise occur when an object of a subclass type is copied to an object of the same type by the superclass's assignment operator, in which case some of the target object's member variables will retain their original values instead of getting copied over from the source object. (en)
rdfs:label Object slicing (en)
owl:sameAs freebase:Object slicing wikidata:Object slicing https://global.dbpedia.org/id/4sqqf
prov:wasDerivedFrom wikipedia-en:Object_slicing?oldid=1098748229&ns=0
foaf:isPrimaryTopicOf wikipedia-en:Object_slicing
is dbo:wikiPageDisambiguates of dbr:Slicing
is dbo:wikiPageRedirects of dbr:Slicing_problem
is dbo:wikiPageWikiLink of dbr:Index_of_object-oriented_programming_articles dbr:Criticism_of_C++ dbr:Cloning_(programming) dbr:Slicing dbr:Slicing_problem
is foaf:primaryTopic of wikipedia-en:Object_slicing