Function addresses in MFC message maps(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)
yields Clang : 获取地址时必须明确限定成员函数的名称
ON_BN_CLICKED(IDC_CHECK1, OnClickedSomeButton)
产生 Clang : 在没有对象参数的情况下调用非静态成员函数
即使您不想发布 MSVC 编译的二进制文件,也最好坚持第一种形式 - 您可能想使用需要 clang 编译的 clang-tidy 等工具.这也是唯一的 C++ 标准符合方式传递成员函数指针.另外两个由微软的扩展工作.
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.
这篇关于MFC 消息映射中的函数地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MFC 消息映射中的函数地址
基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
