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

Is oops and c++ same?

0 Answers  


What is a pointer how and when is it used?

0 Answers  


What are manipulators in c++ with example?

0 Answers  


Why is c++ not purely object oriented?

0 Answers  


Is c the same as c++?

0 Answers  


when can we use copy constructor?

6 Answers   HP,


given unsigned int ui1=3,ui2=7; what are the outputs of a)ui1 & ui2 b)ui1 && ui2 c)ui1 | ui2 d)ui1 || ui2 i also need the justification for the answers thank you

2 Answers  


If you want to share several functions or variables in several files maitaining the consistency how would you share it?

0 Answers  


Who invented turbo c++?

0 Answers  


What are the advantage of using register variables?

0 Answers  


If a header file is included twice by mistake in the program, will it give any error?

0 Answers  


What is the best sorting algorithm, when there is a large amount of data, that cannot be fit in the main memory. ?

1 Answers   Yahoo,


Categories