
when changing protected member to public member
Quote:
>Hi...
>I've changed a protected member variable in afxwin.h to public member
>variable like belows;
Ouch!
Quote:
>------in original file----
>protected :
> HGLOBAL m_hDevMode; // printer Dev Mode
> HGLOBAL m_hDevNames; // printer Device Names
> DWORD m_dwPromptContext; // help context override for message box
>------in changed file
>protected :
> HGLOBAL m_hDevMode; // printer Dev Mode
> HGLOBAL m_hDevNames; // printer Device Names
>public:
> DWORD m_dwPromptContext; // help context override for message box
>so. I can use m_dwPromptContext in my source code. I wonder if the change
>can
>make potential bugs or problems. Let me know the effect of the change. In my
>knowledge,
>there may be some reson to make the varibale protected.
C++ has never guaranteed any particular layout order between sets of
variables in the face of access specifier changes. For example:
struct A
{
public:
int x;
private:
int y;
Quote:
};
struct A could be laid out such that x precedes or follows y. This means
your program could use a different object layout for the class in question
than
MFC, with disastrous results. Will this happen in VC++? I really don't
know, and I'm not too interested in finding out, because this is an example
of the proverbial "bad practice". Even if you discover there is no layout
change, you are creating a lot of problems for yourself. For example, if you
upgrade, you're going to have to make this change in future releases of
VC++, and then there are service packs, which won't update source files
you've modified. IMO, it's a *very* bad idea to turn "MS MFC" into "your
MFC". The MFC and CRT source should be considered read-only, and very
carefully read, so that you don't introduce subtle dependencies on
undocumented behavior into your code.
--
Doug Harrison