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

a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


What are the types of STL containers?

4 Answers  


List the types of polymorphism in c++?

0 Answers  


how is returning structurs from functions?Show an eg?

1 Answers   GE,


What are the various storage classes in C++?

0 Answers   Fidelity,






How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

0 Answers  


Is sorted c++?

0 Answers  


What is c++ map?

0 Answers  


Which operator can not be overloaded in C++?

1 Answers  


Describe linked list using C++ with an example.

0 Answers  


What about Virtual Destructor?

1 Answers   Virtusa,


Why we use #include conio h in c++?

0 Answers  


Categories