Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
234 down vote


"Slicing" is where you assign an object of a derived class to an instance of a base class, thereby losing part of the information - some of it is "sliced" away.

For example,
C++
class A {
   int foo;
};

class B : public A {
   int bar;
};

So an object of type B has two data members, foo and bar

Then if you were to write this:

C++
B b;

A a = b;

Then the information in b about member bar is lost in a.
Posted
Updated 27-Sep-14 2:31am
v2
Comments
[no name] 27-Sep-14 6:41am    
And where is the problem? It's very natural that A can only absorb what it provides. It is the ::= of A which is responsible for that.
[no name] 27-Sep-14 8:27am    
Copying some text from some other website and posting it here as if it were an actual question or answer is highly frowned upon. If you think that this information is noteworthy then write an article. In your own words and not by copying someone else's work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900