【发布时间】:2019-08-03 02:46:28
【问题描述】:
标题已经说过了。
查看真实世界示例,请参阅:https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-findexecutablea
返回一个 HINSTANCE - 它是一个指针类型 - 在某些情况下可以假定预定义的错误值。
最好是,我想打开一个 HINSTANCE 并在不诉诸 const_cast 或 c 样式转换的情况下做到这一点 - 如何实现?
示例代码:
bool test_result(const HINSTANCE ptr) {
switch (ptr) {
case 2 /*SE_ERR_FNF*/:
return false;
default:
return true;
}
}
【问题讨论】:
-
为什么是
switch?为什么不if (hInst == (HINSTANCE)SE_ERR_FNF) { ... }? -
@RogerLipscombe 很好,在实践中还有更多的价值/案例
标签: c++ casting switch-statement c++17