Click here to Skip to main content
15,913,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: overzealous protection rules Pin
Zac Howland12-Jul-06 7:08
Zac Howland12-Jul-06 7:08 
GeneralRe: overzealous protection rules Pin
Dave Schumann12-Jul-06 6:59
Dave Schumann12-Jul-06 6:59 
GeneralRe: overzealous protection rules Pin
Zac Howland12-Jul-06 7:14
Zac Howland12-Jul-06 7:14 
Answersolution Pin
Dave Schumann12-Jul-06 6:04
Dave Schumann12-Jul-06 6:04 
GeneralRe: solution Pin
Dave Schumann12-Jul-06 8:25
Dave Schumann12-Jul-06 8:25 
GeneralRe: solution Pin
BadKarma12-Jul-06 8:58
BadKarma12-Jul-06 8:58 
GeneralRe: solution Pin
led mike12-Jul-06 8:53
led mike12-Jul-06 8:53 
AnswerRe: overzealous protection rules Pin
Rilhas17-Jul-06 13:43
Rilhas17-Jul-06 13:43 
After reading these many posts (although many of them seemed to miss the point entirely) I agree with what as already been stated: the "protected" keyword in A allows access from B to protected members in B inherited from A. Not members from A.

So, there is no real way to make this access legal. B can access all the protected members of B, but not the protected members of A. I do think that this is a design error, although I believe that someone has thought about it and found enough arguments to justify this protection. I would be happy to leave it to the lawyers to argue about it.

Meanwhile, to get around the issue, you could force a static cast on the partner. For example:

struct A
{
A* partner;
void doodah()
{ ++partner->value; } //this is legal
protected:
int value;
};

struct B: public A
{
void foobar()
{ ((B*)partner)->value += 2; } //but this isn’t
};

This code compiles. You may use this code safely because you know that B contains an A. So, the static cast can be used safely if you ensure that you do not use any of B's features on the cast A's partner pointer.

Anyway, with the static cast solution, you can keep the value protected, and still use it from inside B. The code in foobar() is the only one accessing the "value" (this gives you a "per line" control, as oposed to class or function access provided by the use of "friend").

I hope this helps (although I'm sure you will see it as a workaround, I know I do),
Rilhas

AnswerRe: overzealous protection rules Pin
David Crow31-Jul-06 10:28
David Crow31-Jul-06 10:28 
QuestionA (simple) Shell Question Pin
Dave Kerr12-Jul-06 4:49
Dave Kerr12-Jul-06 4:49 
QuestionLabeling Slider Bar stops Pin
LCI12-Jul-06 4:36
LCI12-Jul-06 4:36 
AnswerRe: Labeling Slider Bar stops Pin
pgrohs12-Jul-06 4:51
pgrohs12-Jul-06 4:51 
GeneralRe: Labeling Slider Bar stops Pin
LCI12-Jul-06 5:51
LCI12-Jul-06 5:51 
GeneralRe: Labeling Slider Bar stops Pin
pgrohs12-Jul-06 6:05
pgrohs12-Jul-06 6:05 
QuestionRightToLeft property Pin
Elbaz Haviv12-Jul-06 3:17
Elbaz Haviv12-Jul-06 3:17 
AnswerRe: RightToLeft property [modified] Pin
includeh1012-Jul-06 3:33
includeh1012-Jul-06 3:33 
AnswerRe: RightToLeft property Pin
David Crow12-Jul-06 4:36
David Crow12-Jul-06 4:36 
QuestionLocalization in Input String and Log files. Pin
karthik Tamizhmathi12-Jul-06 3:11
karthik Tamizhmathi12-Jul-06 3:11 
QuestionHow to write KeyboardProc() Pin
Max++12-Jul-06 3:09
Max++12-Jul-06 3:09 
AnswerRe: How to write KeyboardProc() Pin
includeh1012-Jul-06 3:22
includeh1012-Jul-06 3:22 
QuestionItems appear twice in 'Find' results Pin
LittleYellowBird12-Jul-06 3:00
LittleYellowBird12-Jul-06 3:00 
Questioncan ChooseFont use ChooseColor? Pin
includeh1012-Jul-06 2:42
includeh1012-Jul-06 2:42 
AnswerRe: can ChooseFont use ChooseColor? Pin
_AnsHUMAN_ 12-Jul-06 5:03
_AnsHUMAN_ 12-Jul-06 5:03 
GeneralRe: can ChooseFont use ChooseColor? Pin
includeh1012-Jul-06 5:45
includeh1012-Jul-06 5:45 
QuestionComunicating Gina with user mode App or service Pin
Kharfax12-Jul-06 2:25
Kharfax12-Jul-06 2:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.