[英]clang-6 and -std=c++17 — can't invoke bind(2)
Trying to compile the following code using clang++ version 6.0 with the -std=c++17
flag: 尝试使用带有
-std=c++17
标志的clang ++ 6.0版编译以下代码:
if (bind(ssock, res->ai_addr, res->ai_addrlen) != 0)
{
return -1;
}
I get the following error: 我收到以下错误:
.../udt4/app/test.cpp:90:51: error: invalid operands
to binary expression ('__bind<int &, sockaddr *&, unsigned int &>' and
'int')
if (bind(ssock, res->ai_addr, res->ai_addrlen) != 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~
/usr/include/c++/v1/system_error:587:1: note: candidate function not viable: no
known conversion from '__bind<int &, sockaddr *&, unsigned int &>' to
'const std::__1::error_code' for 1st argument
operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
....
Somehow, the perfectly standard function bind(2)
seems to have gotten redeclared as something returning an error_code
instead of the good old int
. 某种程度上,完美标准的函数
bind(2)
似乎已经被重新声明为返回error_code
而不是旧的int
。
What's going on? 这是怎么回事? How do I solve this nicely -- and keep the code compilable with earlier compilers?
我该如何很好地解决这个问题-并使代码与早期的编译器兼容?
You might have using namespace std
or similar in your program, in which case the compiler might think you want std::bind
. 您可能在程序中
using namespace std
或类似using namespace std
,在这种情况下,编译器可能会认为您需要std::bind
。
To refer to the bind you probably really want, you can use ::bind
. 要引用您可能真正想要的绑定,可以使用
::bind
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.