On Mar 10, 7:23 pm, "Harvey" <harve...@juno.com> wrote:
I have read several posts about "warning C4355: 'this' : used in base
member initializer list", and I understand about the object of 'this'
not being fully initialized, but that it is common 'safe' practice to
use this method to only save a pointer for future use..
OK, my question is;
What is the proper or best way to initialize a non-modal dialog?
I have used two methods:
1.)
CFooDlg::CFooDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD, pParent)
{
// pParent is not set here, See Create
pCV=NULL;
}
BOOL CFooDlg::Create(CWnd * pParent)
{
pCV=(CMyBar *) pParent;
}
2.)
CMyBar::CMyBar(CWnd* pParent /*=NULL*/)
: CDialog(CMyBar::IDD, pParent),
CFooDlg( this ) // <---- Warning C4355
{
}
CFooDlg::CFooDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD, pParent)
{
pCV=(CMyBar *) pParent;
}
But method (2) seems more natural but it gives me warning C4355.
Is there a simpler cleaner way?
TIA,
Harvey
To answer my own question...
I now use GetParent() in each function that I need it, as in:
CMyDlg * pP = (CMyDlg *)GetParent(); // If used many times in a
function
pP->m_bSwitch = false;
pP->m_X = X1; // Etc.
or
((CMyDlg *)GetParent())->m_Var = Val; // If used once in a function
The documentation says:
"The returned pointer may be temporary and should not be stored for
later use."
So that would mean that both of my previous methods should be
dangerous because they return the same pointer.
However, when is this not the case?
Or when is it dangerous (or not) to use the pointer "later"?
TIA,
Harvey