|
#1
|
|||
|
|||
|
Hi all,
when we inherit a class in any mode the private variables of base class doesnot come to dervie class (only public or protected member come). But are the private variable of base still present with derived object. bcz if i am making an derived object and type cast it to base. then through any public interface of base class i can get acees to private variables of base. so is it just restrict the acess of private variable or they are not at all present directly or indirectly with derived object Thanks |
|
#2
|
||||
|
||||
|
The private members are still present in the derived class. And yes, you can access them by casting the derived object to the type of the base class. There are in fact several other simpler techniques to circumvent private access to members but remember: the point is not to provide a data encryption mechanism. Private data are a voluntary design decision that is meant to protect you from shooting yourself in the foot.
__________________
Danny Kalev |
|
#3
|
|||
|
|||
|
Hi danny,
Thanks for ur reply .please go through my comments as below: [quote=Danny;523198]The private members are still present in the derived class. [quote] present in the sense how?? they are not private, public or protected member of derived class . we can't also directly access them in derived class member function !!!!! Quote:
|
|
#4
|
||||
|
||||
|
They are present in the sense that they still occupy memory in the derived object, and they undergo initialization and destruction. The fact that you can't access them doesn't mean they don't exist.
*You can use macros to override private: and public: *You can use pointers to char * to access the members by pointing their exact address *You can serialize the object to a file and then read the file's contents *In some cases, you can use pointers to data members to access such members.
__________________
Danny Kalev |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Union query | peljo | Database | 4 | 12-17-2007 12:38 PM |
| SQL2000 remote SQL query | lightningtechie | Database | 1 | 02-07-2006 09:34 AM |
| Multi-table Select Query using Joins | knightsg | Database | 0 | 02-16-2005 09:07 AM |
| reg...select count distinct....query | Mohan Ekambaram | Database | 0 | 12-09-2001 12:56 PM |
| reg....count distinct query | Mohan Ekambaram | Database | 0 | 12-09-2001 12:21 AM |