|
-
Stormtrooper Mod
C++ class access control
Can somebody please offer some insight on the differences between private and protected access controls? I have really never dealt with protected, and every definition I see seems to sound just like the definition for private, which I do use often (of course).
thanks!
Proofread carefully to see if you any words out.
[the rules]
-
Mako Shark
protected is like private with the exception that protected variables/methods can be accessed by the subclass(s) of the class
[This message has been edited by dighn (edited January 01, 2001).]
-
Katana Wielding Moderator
Originally posted by Pinky:
Can somebody please offer some insight on the differences between private and protected access controls? I have really never dealt with protected, and every definition I see seems to sound just like the definition for private, which I do use often (of course).
thanks!
A private member cannot participate in inheritance. Only protected members can.
Example:
Class X:{
Protected:
Int I;
Int J;
Private:
Int L;
Public:
Void get_ij();
Void put_ij();
};
Class Y : public X {
Int k;
Public:
Int get_k;
Void make K;
};
Here class Y has access to I and J in class X because they are protected. But Y does not have access to L, because it is private to class X.
-
Katana Wielding Moderator
Originally posted by Klashe:
A private member cannot participate in inheritance. Only protected members can.
Example:
Class X:{
Protected:
Int I;
Int J;
Private:
Int L;
Public:
Void get_ij();
Void put_ij();
};
Class Y : public X {
Int k;
Public:
Int get_k;
Void make K;
};
Here class Y has access to I and J in class X because they are protected. But Y does not have access to L, because it is private to class X.
Oh yeah, and ignore the caps in that last post. 
-
Stormtrooper Mod
thank you both!
Proofread carefully to see if you any words out.
[the rules]
-
Originally posted by Pinky:
Can somebody please offer some insight on the differences between private and protected access controls? I have really never dealt with protected, and every definition I see seems to sound just like the definition for private, which I do use often (of course).
thanks!
Member Inheritance
Before | After Inherited as
| Pub Pro Pri
-------+--------------------
Pub | Pub Pro Pri
Pro | Pro Pro Pri
Pri | Not Not Not
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|