What is object slicing and how can we prevent it?
Answers were Sorted based on User's Feedback
Answer / prits
When an instance of derived class is assigned to base class
instance object slicing takes place.ie in this case the
derived portion gets truncated and only the base portion
remains.
The problem of object slicing can be prevented by the use
of pure virtual functions.
| Is This Answer Correct ? | 38 Yes | 6 No |
Answer / vikas
Object slicing occurs when we assign an instance of the
subclass to a variable of type base class.
http://www.cppquestions.com/viewtopic.php?f=17&t=49
| Is This Answer Correct ? | 12 Yes | 9 No |
What is the difference between public and private data members?
What is a parameterized type?
Why preincrement operator is faster than postincrement?
What is the standard template library (stl)?
What is iterator in c++?
How can you quickly find the number of elements stored in a dynamic array?
Explain the different access specifiers for the class member in c++.
Why null pointer is used?
Write a String class which has: 1) default constructor 2) copy constructor 3) destructor 4) equality operator similar to strcmp 5) constructor which takes a character array parameter 6) stream << operator
2 Answers HCL, Lehman Brothers, Zoomerang,
How does java differ from c and c++?
Define copy constructor.
What is using namespace std in c++?