Re: Check on correctness
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 01 Jul 2006 23:26:32 -0400
You need to do two things to become a better developer:
Never, ever under any circumstances embed assignments in any other
construct. Not in an if, not in a while, and most especially not in an ASSERT.
Embedded assignment is a very poor programming methodology, and serves
little if any useful purpose at any time and should be abandoned as a
programming technique
Never, ever, under any circumstances make any document or view class visible
to a dialog. Dialogs should only work on their own member variables or
structures used for communication and not know about anything else outsdie
themselves.
joe
On 1 Jul 2006 05:21:56 -0700, "tim@xxxxxxxxxxxxxxxxxxxxxx" <tim@xxxxxxxxxxxxxx> wrote:
Thanks for the reply, sheesh what a chump.Joseph M. Newcomer [MVP]
Yours...one step closer to being a decent developer.
Tim
www.fruitfruit.com wrote:
I had a problem with CMyView->GetDocument() in release.That is due to the fact that ASSERT is ignored in release configuration.
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?
You shall not put initialize code in ASSERT, do it in the following way:
m_pDoc = pParent->GetDocument();
ASSERT(m_pDoc);
This shall work for both Debug and Release.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Check on correctness
- From: Tom Serface
- Re: Check on correctness
- References:
- Check on correctness
- From: tim@xxxxxxxxxxxxxxxxxxxxxx
- Re: Check on correctness
- From: www.fruitfruit.com
- Re: Check on correctness
- From: tim@xxxxxxxxxxxxxxxxxxxxxx
- Check on correctness
- Prev by Date: Re: Check on correctness
- Next by Date: Re: issue with dialog
- Previous by thread: Re: Check on correctness
- Next by thread: Re: Check on correctness
- Index(es):
Relevant Pages
|