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

What are virtual functions and what is its use?

1 Answers  


What is a multiset c++?

0 Answers  


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

0 Answers  


A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.38, and the profit of each carton of milk is $0.27. Write a C++ program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.

2 Answers  


Can we use clrscr in c++?

0 Answers  






What do you mean by persistent and non persistent objects?

1 Answers  


What are files in c++?

0 Answers  


When volatile can be used?

3 Answers   Symphony,


write the programme that convert a interger to biniry number

1 Answers   Amazon,


show that among any group of five (not necessary consecutive ) integers, there are two with the same remainder when divided by 4.

1 Answers  


What operators can you overload in c++?

0 Answers  


Given the following function definition: int doit(int &x, int y, int &z) { x = 3*x; y = y + 5; z = x+y; return z - 4; } int a = 5, b = 7, c = 9, d = 11; d = doit(a,b,c);

2 Answers  


Categories