Can C++ slicing apply to other languages too, like Java/C#?
Slicing means that if you assign a subclass instance to a superclass variable, the extra information contained by subclass is "sliced" off, because the superclass variable doesn't have the extra space to store this extra information of the subclass.
This doesn't happen in Java nor with C#, because all object variables are references; when you assign a subclass instance to a superclass variable, you actually just copy the reference; the subclass object itself remains intact.
Raj, buy a copy of Scott Meyer's excellent book "Effective C++" (sanitised Amazon link) for many excellent discussions about this problem and many other C++ gotchas.
HTH
cheers,
Here's how I understand the slicing problem:
I start with a class Parent, with a method doThis.
I create a new class Child, which inherits the doThis method and defines another method doThat.
I now create an array of Parent references and populate it with references to Parent and Child. If I iterate through that array of Parent references, I can't call the doThat method on any reference without knowing its underlying type and casting to Child where appropriate. I can call doThis on every reference without concern, because every Child IS-A Parent and has a doThis method to call.
The representation of the Child class isn't modified in memory, but the doThat method isn't available via a Parent reference without casting - it's "sliced away".
Perhaps I'm incorrect, but that's how I think of the slicing problem. If that's true, it is indeed present in Java.