Benefits of Protected Construtors in MFC
Hi
I want to ask you about logic behind the protected constructors in MFC.
Firstly i want to give an example. This make easier to explain the problem.
I added a class which is driven from CView class. And i want to show it when
clicked "View->New Window" menu.
***********************
#pragma once
// code view
class code : public CView
{
DECLARE_DYNCREATE(code)
protected:
code(); // protected constructor used by dynamic creation
virtual ~code();
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
DECLARE_MESSAGE_MAP()
};
*************************
I can not call like this:
CView* pView = (CView*) new code; // error C2248 cannot access protected
member
1-) Why are the wizard declare classes constructors protected or private?
What is the benefit/logic? For example If i add class which is derived from
CEdit with wizard, its constructors is declared public but if it is derived
from CEditView its constructor is declared protected. Why is that so?
2-)Is changing protected to public best way?
3-) Where must i handle the menu selection, i mean creating new form. In
MainFrm.cpp or something else?
If you help me to understand this concept i will be very glad