我正在尝试解决我遇到的MSVC 2015中的错误(请参阅此问题: 函数签名的错误类型推导).
所以我想出了这个:
#include<Windows.h>
namespace wreg {
using t_oshandle = HKEY;
struct t_api
{
static constexpr
auto fnc_open_key () { return ::RegOpenKeyExA; }
//this doesn't compile :
static constexpr auto open_key = fnc_open_key();
//these don't compile either:
//static constexpr decltype(fnc_open_key()) open_key = fnc_open_key();
//static constexpr decltype(::RegOpenKeyExA) open_key = fnc_open_key();
};
//this does compiles and runs :
constexpr auto open_key = t_api::fnc_open_key();
} // namespace wreg
//int main( int argc ,_TCHAR* argv[] );
{
auto hk = wreg::t_oshandle{};
auto …Run Code Online (Sandbox Code Playgroud) 这很像这个问题为什么在C和C++中算术运算之前必须将short转换为int? 但是有一个子问题,为什么编译器在一种情况下诊断警告而在另一种情况下诊断错误,具有完全相同的表达式.
我非常喜欢在...中使用auto'type' auto var =,但是MSVC 2015 CTP在我的代码中给出了错误.
问题是我是auto一个类型的表达,short但有时它被提升为int.
这是一个MCVE:
struct MY_COORD { short X; short Y; };
using t_crd = MY_COORD;
void call_test ( t_crd x ) {}
int main()
{
t_crd crd { 10 ,20 };
auto x5 = crd.X - crd.Y;
auto y5 = crd.Y - crd.X;
t_crd crd5 { x5 ,y5 }; // (1)
call_test( t_crd{ x5 ,y5 } ); // (2)
}
Run Code Online (Sandbox Code Playgroud)
来自第(1)和(2)行的消息分别是:
warning C4838: …Run Code Online (Sandbox Code Playgroud) 许多年前我了解到,为了使用GetMessage,您需要某种形式的GUI.没有它,Windows不会创建消息队列.
我被错误地教导了吗?
编辑:MSDN说:因为系统将消息定向到应用程序中的各个窗口,所以线程必须在启动其消息循环之前创建至少一个窗口.
看来我教的很好,还是有更多?