Function addresses in MFC message maps

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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.

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!