I am trying a workaround in MSVC 2015 that I encountered (see this question: incorrect output of type of function signature ).
So, I came up with this:
#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 res = wreg::t_api::open_key( HKEY_LOCAL_MACHINE ,"SOFTWARE" ,0 ,KEY_READ ,&hk ); //auto res = wreg::open_key( HKEY_LOCAL_MACHINE ,"SOFTWARE" ,0 ,KEY_READ ,&hk ); if (res == ERROR_SUCCESS) { res = ::RegCloseKey( hk ); } return 0; }
but it does not compile due
error C3779: 'wreg :: t_api :: fnc_open_key': a function that returns 'auto' cannot be used until it is defined
I do not understand. It is clearly defined in the place in which I use it. And besides, in a class usually the names used by the local definition of the class can be used before its definition / declaration.
Question: Why is MSVC correct or should my code compile?
source share