Skip to content

Instantly share code, notes, and snippets.

@garethlewin
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethlewin/8931239 to your computer and use it in GitHub Desktop.
Save garethlewin/8931239 to your computer and use it in GitHub Desktop.
// Why does this work:
int addrInfoRet = getaddrinfo(host.c_str(), port.c_str(), &hints, &remoteHost);
auto deleter = [](addrinfo* p){ if (p) {freeaddrinfo (p);} };
std::unique_ptr<addrinfo, decltype(deleter)> remoteHostContainer(remoteHost, deleter);
// But this doesn't:
int addrInfoRet = getaddrinfo(host.c_str(), port.c_str(), &hints, &remoteHost);
std::unique_ptr<addrinfo, decltype(freeaddrinfo)> remoteHostContainer(remoteHost, freeaddrinfo);
//(Error spam is):
/*
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(1221): warning C4180: qualifier applied to function type has no meaning; ignored
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(1283) : see reference to class template instantiation 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>' being compiled
1> with
1> [
1> _Ty=addrinfo,
1> _Dx=void (PADDRINFOA),
1> _Empty_deleter=false
1> ]
1> x:\dev\sdk\twitchsdk\twitchcore\source\win32\socket.cpp(106) : see reference to class template instantiation 'std::unique_ptr<_Ty,_Dx>' being compiled
1> with
1> [
1> _Ty=addrinfo,
1> _Dx=void (PADDRINFOA)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(1227): error C2207: 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>::_Mydel' : a member of a class template cannot acquire a function type
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(1322): warning C4180: qualifier applied to function type has no meaning; ignored
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment