Studying some sources I often came to see this: (Part of the real source)
void CUserMng::AddText( LPCTSTR szMessage )
{
map<u_long,CUser*>::iterator it;
for( it = m_users.begin(); it != m_users.end(); ++it )
{
CUser *pUser = it->second;
if( !IsValidObj( pUser ) )
continue;
(pUser)->AddTextNotice( szMessage );
}
}
What do the parentheses around pUser
means?
I came up with:
struct bar
{
int value;
}
void foo()
{
bar *ptr = NULL; //new bar;
(ptr)->value = 1;
//delete bar
}
My guess was that a call with parentheses "(ptr)
" was to prevent a call to be made if the pointer was invalid, but it seems its not. Another example I often see is:
classB* ptr = new classB;
((classA*)ptr)->callfunctionfromclassA;