I just came across something I don't quite understand. I thought that static_cast<TYPE>(variable) was equivalent (or better/safer) than TYPE(variable). However, the following code DOES not work
HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();
// File
AppendMenu(hSubMenu, MF_STRING, WndClass_main::ID_FILE_EXIT, "&Quit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, static_cast<intptr_t>(hSubMenu), "&File");
My compiler says that it can't convert from HMENU to intptr_t. I have a 64-bit system btw, which interfers with the casting between void* and int? However, from what I understand the type intptr_t (defined in cstdint) is guaranteed to be big enough for a void*.
The interesting part is that the following (note the different cast) works:
HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();
// File
AppendMenu(hSubMenu, MF_STRING, WndClass_main::ID_FILE_EXIT, "&Quit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (intptr_t)(hSubMenu), "&File");
What am I missing?