Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is object slicing?

Answer Posted / chris pearson

"Object slicing" is an informal term that is often used (as
in all the answers above) to indicate that (in some
languages, usually C++) assignment to a superclass instance
from a subclass instance does not copy the member variables
defined only in the subclass.

This usage of the term is inapt and misleading, for several
reasons:

1. The notion that an object has been damaged ("sliced")
suggests something to be avoided. However, it is not
possible (or meaningful) in any statically typed language
for a superclass instance to contain subclass member
variables, so in fact assignment to a superclass operates
correctly and is a useful language feature.

2. After such an assignment, the source, subclass, object
remains unchanged, so it has in no sense been been "sliced".

3. After such an assignment, all member variables of the
destination, superclass, object are present and have been
assigned values, so neither has it in any sense
been "sliced".

The case to which the term "object slicing" is better
applied is more subtle and problematic. It occurs in a
statically typed language such as C++ where assignment
appears to be to a superclass instance but is actually to a
subclass instance.

For example:

void myassign(mysuperclass &dest)
{
mysuperclass source;
dest = source;
}

mysubclass sub;
myassign(sub); // assigns only superclass members of
sub!

A better term for this case might be "partial assignment".

Such partial assignment is not possible in Java because
that language only allows object references, and assignment
to a reference simply causes it to refer to a different
object.

-- Chris

Is This Answer Correct ?    9 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is difference between class template and template class?

2596


Which type does string inherit from?

1061


What is polymorphism in oop example?

960


what is the sylabus for priliminaries?

2122


#include #include #include #include void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

3700


write a program that takes input in digits and display the result in words from 1 to 1000

2370


Advantage and disadvantage of routing in telecom sector

1249


What is overloading in oop?

959


Can we create object of abstract class?

1029


c++ program to swap the objects of two different classes

2358


Can destructor be overloaded?

978


Why do we use inheritance?

1061


Can we override main method?

1122


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

1241


How many human genes are polymorphic?

1001