Re: Check on correctness
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 01 Jul 2006 23:23:39 -0400
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.Joseph M. Newcomer [MVP]
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?
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Check on correctness
- From: tim@xxxxxxxxxxxxxxxxxxxxxx
- Check on correctness
- Prev by Date: Re: file can not be open, read or write in visual studio 2005
- Next by Date: Re: Check on correctness
- Previous by thread: Re: Check on correctness
- Next by thread: file can not be open, read or write in visual studio 2005
- Index(es):
Relevant Pages
|
Loading