Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 25-03-2011, 06:47 PM   #1 (permalink)
BIOS Terminator
 
nims11's Avatar
 
Join Date: Apr 2008
Location: Ranchi
Posts: 816
Default a simple OOP doubt


please clear my doubt
if a class A inherits from B, then why would the private members of the base class B will contribute to the size of the object of derived class A?


P.S.- C.Sc board exam on 30th!!
nims11 is online now   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 25-03-2011, 07:19 PM   #2 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: a simple OOP doubt

It's because the private members do exist in the memory, and are actually there with the class and they are only inaccessible to the derived class members and objects. The public base methods which are inherited WILL be able to access, modify the base members.
It could very well be that you are modifying the private members through the public methods of the class. For instance:

Code:
class B    {
   private:
       int var;
   public:
       void modify_var(int v)    {
           var = v;
        }
};


class A : public B   {
   private:
        int num;
   public:
       void modify_A_var(int v, int n) {
           modify_var(v);
           num = n;
        }
};
You can see in modify_A_var() in class A is accessing a private member of class A only albeit through a member function of the base class.

P.S.: My C++ is rusty, not programmed for over a year, feel free to correct if my post is wrong or has errors.
P.P.S.: Best of luck for the exam
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline   Reply With Quote
Old 25-03-2011, 09:11 PM   #3 (permalink)
Wise Old Owl
 
pulkitpopli2004's Avatar
 
Join Date: Jul 2010
Location: D!ll!
Posts: 1,131
Default Re: a simple OOP doubt

yeah hez right
__________________
I'd explain it to you, but your brain would explode... Trust me :hot:
i5 760, Asus P7P55D-EVO, Zotac GTX 460, VX550, Win7 64bit,4GB RAM @1600MHz, WD 500GB Caviar Black
pulkitpopli2004 is online now   Reply With Quote
Old 25-03-2011, 09:25 PM   #4 (permalink)
BIOS Terminator
 
nims11's Avatar
 
Join Date: Apr 2008
Location: Ranchi
Posts: 816
Default Re: a simple OOP doubt

Thanx a lot LFC_fan.

i played with the code and now everything is clear!! my appreciation for OOP has increased after understanding this...
nims11 is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx
- by clinton

Advertisement




All times are GMT +5.5. The time now is 12:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2