What is object slicing and how can we prevent it?

Answers were Sorted based on User's Feedback



What is object slicing and how can we prevent it?..

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

What is object slicing and how can we prevent it?..

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

Post New Answer

More C++ General Interview Questions

Describe linked list using C++ with an example.

0 Answers  


Does there exist any other function which can be used to convert an integer or a float to a string?

0 Answers  


How do you differentiate between overloading the prefix and postfix increments?

0 Answers  


Mention the ways in which parameterized can be invoked. Give an example of each.

0 Answers  


What ANSI C++ function clears the screen a) clrscr() b) clear() c) Its not defined by the ANSI C++ standard

0 Answers  






What are the various access specifiers in c++?

0 Answers  


Will c++ be replaced?

0 Answers  


What are the two main components of c++?

0 Answers  


What is std :: endl?

0 Answers  


What do you mean by vtable and vptr in c++?

0 Answers  


Why is it difficult to store linked list in an array?

6 Answers   Infosys, Lucent,


What is the role of static keyword for a class member variable?

0 Answers  


Categories