when changing protected member to public member 
Author Message
 when changing protected member to public member

Hi...

I've changed a protected member variable in afxwin.h to public member
variable like belows;

------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.




Mon, 09 Jul 2001 03:00:00 GMT  
 when changing protected member to public member
Hi...

I've changed a protected member variable in afxwin.h to public member
variable like belows;

------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.




Mon, 09 Jul 2001 03:00:00 GMT  
 when changing protected member to public member
Hi...

I've changed a protected member variable in afxwin.h to public member
variable like belows;

------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.




Mon, 09 Jul 2001 03:00:00 GMT  
 when changing protected member to public member
Hi...

I've changed a protected member variable in afxwin.h to public member
variable like belows;

------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.




Mon, 09 Jul 2001 03:00:00 GMT  
 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



Tue, 10 Jul 2001 03:00:00 GMT  
 when changing protected member to public member
You should never have to turn protected members into public ones.

Just derive from CWinApp, and add

DWORD GetPromptContext()
{
    return m_dwPromptContext;

Quote:
}

void SetPromptContext(DWORD newContext)
{
    m_dwPromptContext = newContext;

Quote:
}

to your derived class.
Quote:

>Hi...

>I've changed a protected member variable in afxwin.h to public member
>variable like belows;

>------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



Thu, 12 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Changing a CView derived classe's m_pDocument protected member

2. Bug or Feature, cannot access protected member

3. Accessing Protected Members

4. TcpClient and its protected member Client() or

5. Implementing interface members as protected?

6. access to private or protected members

7. Access to protected member variables??

8. protected members and inheritance

9. Funny warning C4248: cannot access protected member

10. Bug?? Protected member access

11. ??accessing protected members???

12. Protected member in a base class of a base class

 

 
Powered by phpBB® Forum Software