Check on correctness



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?

.



Relevant Pages

  • Re: defining classes-- different methods
    ... reference to the function assigned to its - constructor - property, ... which is not true of an object assigned to the prototype property of a ... prototype Thus it is wasteful of resources to be assigning function ... not employing closures to emulate private members. ...
    (comp.lang.javascript)
  • Re: "Reconstructing" (Calling the constructor again)
    ... A constructor can only be called once ... /* This dynamically allocates a type 'Foo' object, ... You're *assigning* '*aFoo' a new value. ... initializes the temporary object, it does not affect ...
    (comp.lang.cpp)
  • Re: How to make an object instance available to all members of a page?
    ... Assigning default value is a logical exception from that rule. ... Contract StockContract = new Contract; ... into play because of the Dictionary/Sections properties. ... If you move it to constructor then default value will become null... ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to make an object instance available to all members of a page?
    ... Assigning default value is a logical exception from that rule. ... Contract StockContract = new Contract; ... into play because of the Dictionary/Sections properties. ... If you move it to constructor then default value will become null... ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: WITH (this) {a;b;c}
    ... Unlike class-based object languages, ... objects dynamically by assigning values to them. ... object augmentation even after leaving the constructor: ... is not an obvious feature for say C++ programmer so requires a special ...
    (comp.lang.javascript)