Whats the meaning of this code

S

sam

Hi,
Whats the meaning of this code:-
((CCommunityDlg*)m_pWnd)->OnClose();
I know this is of VC++,
But I just want to know what the logic behiind this cide,
Please givve me solution
Thanks in advance.
 
V

Victor Bazarov

sam said:
Whats the meaning of this code:-
((CCommunityDlg*)m_pWnd)->OnClose();
I know this is of VC++,
But I just want to know what the logic behiind this cide,

Whatever 'm_pWnd' is, it's being cast to a pointer to 'CCommunityDlg'
and then a member 'OnClose' is called for the object to which that
pointer points after the cast. Same as

CCommunityDlg *pCommunityDlg = (CCommunityDlg*)m_pWnd;
pCommunityDlg->OnClose();

A C-style cast corresponds to either 'static_cast' or 'reinterpret_cast'
or 'const_cast', depending on the declaration of 'm_pWnd' variable.

V
 
M

Marcus Kwok

sam said:
Whats the meaning of this code:-
((CCommunityDlg*)m_pWnd)->OnClose();

m_pWnd is a pointer of some type. It gets casted (possibly unsafely) to
a pointer to a CCommunityDlg. It then calls the OnClose() method of the
CCommunityDlg class. If m_pWnd is something that can not be safely
converted to a CCommunityDlg*, then it will produce undefined behavior.
 
R

Ron Natalie

Victor Bazarov wrote:
\
A C-style cast corresponds to either 'static_cast' or 'reinterpret_cast'
or 'const_cast', depending on the declaration of 'm_pWnd' variable.
Or const_cast combined with static or reinterpret casts.
Or a protection busting cast for which there is no "new-style" cast
equivelent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top