Re: Check on correctness



You should not be calling any method of a parent class in a dialog. A dialog should be
completely oblivious to what its parent might be. It should also not be accessing the
document class.

What is bad practice is having any knowledge in the CDialog-derived class of any view or
document class at all.
joe

On 1 Jul 2006 04:31:45 -0700, "tim@xxxxxxxxxxxxxxxxxxxxxx" <tim@xxxxxxxxxxxxxx> wrote:

I had a problem with CMyView->GetDocument() in release.

Within the constructor of the dialog class, I assigned the attribute,
m_pDoc to the document

ASSERT(m_pDoc = pParent->GetDocument());

In release, my program would throw an exception because m_pDoc was
NULL. I trawled through google, to see this is a common error (also
reading that I should call GetDocument every time rather than assigning
to an attribute).

However, if I assign m_pDoc within the dialog's initialisation list the
attribute is assigned correctly.

CExternalEffectorDlg::CExternalEffectorDlg(CState_SdiView*
pParent,const int AtomIndex)
: CDialog( CExternalEffectorDlg::IDD, pParent ),
m_pDoc( pParent->GetDocument() ),


Is calling a getter in an initialisation list bad practice?
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: how to invoke Tcl_DupInternalRepProc for testing
    ... includes assigning a Tcl_DupInternalRepProc function. ... purposes I'd like to provoke Tcl into calling my Tcl_DupInternalRepProc ...
    (comp.lang.tcl)
  • Re: How do I use a different NIC in Small Business Server 2003?
    ... assigning the IP information that was on the first one, reboot, and running ... the Internet Connection Wizard? ... Calling an illegal alien an "undocumented worker" is like calling a ...
    (microsoft.public.windows.server.sbs)
  • Re: header problem - chaptername without "Chapter X."?
    ... \Chapter is not defined in any of the basic classes, so you are presumably using some other document class you haven't told us about. ... tell us what document class you are using. ... If there is no package to do what you want, then the procedure is to find the command causing the effect by looking in the .cls or .sty file, copy it to your own .sty file, and change it there. ...
    (comp.text.tex)
  • Re: Outlook 2003 PIA Question
    ... I am trying to run this sample code but keep getting an "Invalid Cast" ... exception when calling oItems.GetFirst and assigning the resulting ...
    (microsoft.public.outlook.interop)
  • how to invoke Tcl_DupInternalRepProc for testing
    ... includes assigning a Tcl_DupInternalRepProc function. ... purposes I'd like to provoke Tcl into calling my Tcl_DupInternalRepProc ...
    (comp.lang.tcl)

Loading