Click here to Skip to main content
15,881,701 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am new in c++ programming. Can anybody explain me the meaning of below statements.
C++
unsigned long __stdcall CPlaybackDlg::ControlExecuteThreadEntry(void *pParent)
{
	CPlaybackDlg *pTmp = (CPlaybackDlg*)pParent;
}

where CPlaybackDlg is derived from CDialog.

Thanx in advance
Posted

C++
CPlaybackDlg *pTmp = (CPlaybackDlg*)pParent;


That is a C-like cast of a void pointer to a CPlaybackDlg object one.

With such a statement you are telling to the compiler: "I know what I am doing: I know that pParent in spite of being a void * is really a PlaybackDlg*, hence you have to handle it consequently".

Such a idiom is frequently used for passing parameter to thread functions (see, for instance this MSDN example[^]).
 
Share this answer
 
v3
Comments
Mohibur Rashid 8-Jan-13 22:16pm    
Excellent one
hi,
the pParent is a void pointer i.e. a pointer which can point to objects of any type.The void pointer does not know what type of object it is pointing to, so the void pointer must first be explicitly cast to another pointer type before it can be dereferenced.

And you want a pointer pTmp of type CPlaybackDlg which should point at the same object as pParent . So pParent is typecast to type CPlaybackDlg by placing (CPlaybackDlg*) in front of it and this typecast is used to initialize pTmp .

know more about void pointers here[^]
some info on typecasting here[^]

hope this helps .
 
Share this answer
 
Also be aware that if you don't do anything with the pointer, nothing useful happens in this method. It is like doing

C++
void blah()
{
  int doNothing = 42;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900