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

查看:343
本文介绍了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.

这篇关于MFC消息映射中的函数地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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