MFC消息映射中的函数地址
为什么类向导生成的消息映射中的函数地址写有明确提到的类名?
Why are function addresses in message maps generated by the class wizard written with the name of the class explicitely mentioned?
例如:
ON_BN_CLICKED(IDC_CHECK1, &CMyDlg::OnClickedSomeButton)
代替:
ON_BN_CLICKED(IDC_CHECK1, &OnClickedSomeButton)
甚至:
ON_BN_CLICKED(IDC_CHECK1, OnClickedSomeButton)
所有三个变体都能正确编译.
All three variants compile correctly.
这只是好奇心.
所有三个变体都能正确编译.
All three variants compile correctly.
是的,它们可以在MSVC上正确编译.如果尝试使用Clang(Microsoft兼容模式)编译第二个或第三个示例,则会收到错误消息.
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)
产量Clang : must explicitly qualify name of member function when taking its address
ON_BN_CLICKED(IDC_CHECK1, OnClickedSomeButton)
产量Clang : call to non-static member function without an object argument
即使您从不希望通过MSVC编译的二进制文件发行产品,也最好坚持使用第一种格式-您可能希望使用需要clang编译的clang-tidy之类的工具.这也是符合C ++标准的方式传递成员函数指针.其他两个通过Microsoft的扩展来工作.
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.