Why are function addresses in message maps generated by the class wizard written with the name of the class explicitely mentioned?
For example:
ON_BN_CLICKED(IDC_CHECK1, &CMyDlg::OnClickedSomeButton)
instead of:
ON_BN_CLICKED(IDC_CHECK1, &OnClickedSomeButton)
or even:
ON_BN_CLICKED(IDC_CHECK1, OnClickedSomeButton)
All three variants compile correctly.
It's just curiosity.
All three variants compile correctly.
Yes, they compile correctly...on MSVC. If you try to compile the second or third example in Clang (Microsoft compatibility mode) you will get an error.
ON_BN_CLICKED(IDC_CHECK1, &OnClickedSomeButton)
yields Clang : must explicitly qualify name of member function when taking its address
ON_BN_CLICKED(IDC_CHECK1, OnClickedSomeButton)
yields Clang : call to non-static member function without an object argument
It's definitely better to stick to the first form even if you never want to ship other than MSVC-compiled binaries - you might want to use tools like clang-tidy which require clang compilation. It is also the only C++ standard-conformant way to pass a member function pointer. The other two work by Microsoft's extension.