What is slicing?
Answer / atul shankhwar
Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object.
Explanation:
Consider the following class declaration:
class base
{
...
base& operator =(const base&);
base (const base&);
}
void fun( )
{
base e=m;
e=m;
}
As base copy functions don't know anything about the derived only the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.
| Is This Answer Correct ? | 0 Yes | 0 No |
Which c++ compiler is best?
What are single and multiple inheritances in c++?
what do you mean by memory management operators
Describe the advantages of operator overloading?
Evaluate: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); a) 10 b) 11 c) 1
What is the use of class in c++?
What is pointer in c++ with example?
What are the advantages and disadvantages of using inline and const?
2 Answers Polaris, TCS, Zimmer Biomet,
Can a Structure contain a Pointer to itself?
Is java the same as c++?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
What is c++ programming language?