Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-25-2009, 10:46 AM
kaibalya kaibalya is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
Question inheritance query

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
Reply With Quote
  #2  
Old 10-25-2009, 10:57 AM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
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
Reply With Quote
  #3  
Old 10-25-2009, 11:35 AM
kaibalya kaibalya is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
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:
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.
Can u please specify what are the other techniques and elaborate this point bit more??
Reply With Quote
  #4  
Old 10-26-2009, 06:34 AM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
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
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT -4. The time now is 10:42 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.