Sunday, August 9, 2009

POINTES TO DERIVED CLASSES

WE CAN USE POINTERS NOT ONLY TO THE BASE OBJECTS OF DERIVED CLASSES.Therefore to the objects of a base class are type-compatiable wiht pointers to objects of derived class .therefore a single pointer variable can be made to the point to the objects of aderived belonging to different classes.For examole if B is a base class and D is a derived classes.For example be a pointer of D.consider the following declerations.
B *cptr;
B d;
D d;
cptr=&b;
we can make cptr to point to the object d is follows
cptr=&d
The perfectly valid with c++ because d is an object derived from the class b however there is a problem in using cpr we can access onle those members inherited from B and not the members of B,then any reference to that membr by cptr will always access the basic class members.

No comments:

Post a Comment