Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Get a child window? Pin
ThatsAlok11-May-06 5:00
ThatsAlok11-May-06 5:00 
QuestionHow to Interpret this in plain language Pin
Scorpio10-May-06 22:15
Scorpio10-May-06 22:15 
AnswerRe: How to Interpret this in plain language Pin
Cedric Moonen10-May-06 22:18
Cedric Moonen10-May-06 22:18 
GeneralRe: How to Interpret this in plain language Pin
Scorpio10-May-06 22:26
Scorpio10-May-06 22:26 
GeneralRe: How to Interpret this in plain language Pin
Cedric Moonen10-May-06 22:32
Cedric Moonen10-May-06 22:32 
GeneralRe: How to Interpret this in plain language Pin
ThatsAlok11-May-06 4:59
ThatsAlok11-May-06 4:59 
GeneralRe: How to Interpret this in plain language Pin
Cedric Moonen11-May-06 5:02
Cedric Moonen11-May-06 5:02 
AnswerRe: How to Interpret this in plain language Pin
Stephen Hewitt11-May-06 2:41
Stephen Hewitt11-May-06 2:41 
This basically is "saying" the following:
 "Regardless of the type of the variable m_pDlg points to treat it as if it was a CEchoServerDlg; call the OnAccept method through this pointer."
This will obviously cause problems if you cast an object into something its not.

For example:
// Bad code.
CRect rc;
CRect *pNotAWindowAtAll = &rc;
DWORD dwStyle = ((CWnd*)pNotAWindowAtAll)->GetStyle();


This code will compile and run. At best it will crash at runtime and at worst it will not: it will not work correctly and it makes no sense whatsoever. A C-style cast like this just pretends that a CRect is a CWnd but the two classes are not related and it will end in tears. A cast like that is saying to the compiler, "just do what I say".

I often go on about this, but in my opinion (and that of most modern C++ programming books) the C-style cast has no place in modern C++ code. You should use something like this instead:
static_cast<CEchoServerDlg*>(m_pDlg)->OnAccept();


A static_cast will limit the type of cast. It will only cast between related classes, perform standard conversions and call user defined conversion operators. If used in my "bad code" example it will not compile - this is good: nonsense shouldn't compile.


Steve
QuestionDynamic creation of controls Pin
Scorpio10-May-06 22:08
Scorpio10-May-06 22:08 
AnswerRe: Dynamic creation of controls Pin
Cedric Moonen10-May-06 22:13
Cedric Moonen10-May-06 22:13 
GeneralRe: Dynamic creation of controls Pin
Scorpio10-May-06 22:18
Scorpio10-May-06 22:18 
Questionhow tocopy a file to specific folder in ftp Pin
Vivek krishna10-May-06 21:36
Vivek krishna10-May-06 21:36 
AnswerRe: how tocopy a file to specific folder in ftp Pin
Iain Clarke, Warrior Programmer10-May-06 22:44
Iain Clarke, Warrior Programmer10-May-06 22:44 
GeneralRe: how tocopy a file to specific folder in ftp Pin
Vivek krishna10-May-06 22:51
Vivek krishna10-May-06 22:51 
AnswerRe: how tocopy a file to specific folder in ftp Pin
Hamid_RT10-May-06 23:04
Hamid_RT10-May-06 23:04 
AnswerRe: how tocopy a file to specific folder in ftp Pin
Ganesh_T11-May-06 2:13
Ganesh_T11-May-06 2:13 
QuestionDialog with background as Image? Pin
Andy Rama10-May-06 21:19
Andy Rama10-May-06 21:19 
AnswerRe: Dialog with background as Image? Pin
Nishad S10-May-06 21:36
Nishad S10-May-06 21:36 
GeneralRe: Dialog with background as Image? Pin
Andy Rama10-May-06 21:48
Andy Rama10-May-06 21:48 
GeneralRe: Dialog with background as Image? Pin
Nishad S10-May-06 21:51
Nishad S10-May-06 21:51 
GeneralRe: Dialog with background as Image? Pin
Andy Rama10-May-06 22:48
Andy Rama10-May-06 22:48 
GeneralRe: Dialog with background as Image? Pin
Nishad S10-May-06 22:52
Nishad S10-May-06 22:52 
GeneralRe: Dialog with background as Image? Pin
Nishad S10-May-06 23:01
Nishad S10-May-06 23:01 
GeneralRe: Dialog with background as Image? Pin
Andy Rama10-May-06 23:24
Andy Rama10-May-06 23:24 
GeneralRe: Dialog with background as Image? Pin
Nishad S10-May-06 23:35
Nishad S10-May-06 23:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.