MFC 消息映射中的函数地址 [英] Function addresses in MFC message maps

查看:15
本文介绍了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 消息映射中的函数地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆