|
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
|
|
|
|
|
Note that for "plain value" the compiler knows that the value is a member of a B; for "partner->value" it only knows that value is a member of an A.
There is a rule that says that "protected" gives access only to a base of an object of "your own class." That rule was introduced after some pretty horrific bugs appeared where the equivalent to "partner" in your code pointed to a completely different class C that just happened to have the same base (A). There is a discussion of this in D&E.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I am currently writing a namespace extension. I have an IShellFolder implementation, that implements such functions as 'SetNameOf' (called when the user renames an item). However, after calling SHChangeNotifiy (with PIDLs fully qualified, i.e relative to the desktop) my IShellView DOESN'T refresh the changes.
I haven't implemented my own IShellView, I use one created by SHCreateShellFolderView. I would imagine this IShellView would automatically respond to SHChangeNotify, but it doesn't. If I force a refresh by hitting F5 the correct renamed file is then displayed.
Does anyone have any ideas as to why SHChangeNotify isn't working? Any help would be appreciated.
Many thanks,
Dave
Dave Kerr
codechamber@hotmail.com
http://www.codechamber.com
|
|
|
|
|
Is there any way to label the stops on a slider control?
E.g.
| | |
-1 0 1
|
|
|
|
|
Yes, you have to draw it your own.
|
|
|
|
|
Would this be done using owner draw?
|
|
|
|
|
|
I have a dialog based app with a control edit in it.
orginaly writen in vc6 and upgraded to .NET/winxp
How I can Set the RightToLeft property for the edit
cotrol on/off at run time.
I'm vary THANK YOU in advanced.
Elbaz Haviv
Elbaz Haviv
|
|
|
|
|
i have some expeirence with combo-box.
styles of combo-box can not be changed at run time (i.e. from DropDown to DropDown-list).
so when I needed to change its style, I deleted the control then created a new one - looks not good but it worked fine.
I never use edit in your way, but u may use my idea if modification at run time is not possible.
-- modified at 9:36 Wednesday 12th July, 2006
|
|
|
|
|
Not all styles can be changed at run-time. You can try ModifyStyle() to see if it works in this situation. You may find it easier to have two edit controls on the dialog template, one with the WS_EX_LTRREADING style and the other with the WS_EX_RTLREADING style. Then just show/hide the controls accordingly.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dear all,
I need to re-engineer a very big existing source code(Mostly Non-MFC) for localization support.
For that the user input strings should be capable of support in the native language character set throughout the project.
Moreover i have to translate the log files in to regional language based on the language selection.
Kindly refer the Ted's article.
http://www.codeproject.com/cpp/mult_lang_support.asp[^]
Kindly suggest me in this regard.
Regards,
Karthik M
|
|
|
|
|
About Keyboard Hook
If I want my program can get the key more than one key such as Ctrl+Shift+Z before execute some command.
How to write the code in KeyboardProc() function.
|
|
|
|
|
GetKeyboardState() can get states of 256 keys at same time.
|
|
|
|
|
When I perform a 'Find' in my current VS2005 project, some of the files in my project get searched twice. So a word which occurs once in that file appears as two identical results from the 'find'.
Anyone know why? Can I clear it somehow?
Thanks for any suggestions
Ali
|
|
|
|
|
ChooseFont or CFontDialog has few of colors, I want to change font color by ChooseColor or CColorDialog when CFontDialg is displaying, is it possible?
|
|
|
|
|
I did this OnOK Button of a dialog
CColorDialog *cDlg=new CColorDialog();
COLORREF myColor;
if(IDOK==cDlg->DoModal ())
{
myColor=cDlg->GetColor ();
}
HDC hdc=::GetDC(m_hWnd);
SetTextColor (hdc,myColor);
TextOut (hdc,10,100,"hello",5);
::ReleaseDC(m_hWnd,hdc);
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
u just made my post sick!
|
|
|
|
|
Hi
There is any way to communicate events, lets say "user loged in", "user logged off", from the GINA to a user mode App or service?
I mean, I know that I can write a file, or a registry key, and my app can read the info from there but I was looking for other way.
Thanks a lot people
Sebastian
|
|
|
|
|
If it was a usermode app, how would it get started before GINA for the first login after a reboot?
You could use shared memory, but you might want to think about what security descriptor to put on it, depending on what you actually write into it. ISTR that the late lamented Windows Developer Journal had a set of articles about communicating logon/logoff to apps.
Steve S
Developer for hire
|
|
|
|
|
Yeap I understand what you mean Steve, the login couldn't be handled that way...
I don't like the shared memory because that means a usermode app also is going to be able to modify data in the Gina, and that's not good at all.
I'll try to find those articles you talk about.
Thanks a lot
|
|
|
|
|
I have found a great supported way, maybe in the future this will be usefull for someone.
Just google "Winlogon Notification Package"
|
|
|
|
|
F***ing useless, Vista doesn't support this
|
|
|
|
|
hi
tell me some function in mfc with example as i want to know a member function daily as i am new to vc++
thanks
Ashish Dogra
MCA
Noida
-- modified at 9:11 Wednesday 12th July, 2006
|
|
|
|
|
what do you mean by Super Function?
|
|
|
|
|
super means any good function that help me alot and with which something interstig thing can be handled
thanks for ur reply
Ashish Dogra
MCA
Noida
|
|
|
|