I'm using g++ 4.6.0 to compile some C++ code that successfully compiled in earlier versions.
if ( bind(iControl, (struct sockaddr *) &sa, sizeof(sa)) == -1)
throw runtime_error ("bind");
where iControl is a socket, and sa is a struct sockaddr_in
.
However, in g++ 4.6 I get the following error:
comms.cpp:93:66: error: no match for ‘operator==’ in ‘std::bind(_Functor&&, _ArgTypes&& ...) [with _Functor = int&, _ArgTypes = {sockaddr*, long unsigned int}, typename std::_Bind_helper<_Functor, _ArgTypes>::type = std::_Bind<int(sockaddr*, long unsigned int)>]((* &((sockaddr*)(& sa))), (* &16ul)) == -0x00000000000000001’
comms.cpp:93:66: note: candidates are:
followed by about a page and a half of possible candidates.
It appears to be mixing up the bind function in sys/sockets.h
with std::bind in functional
. How do I disambiguate the two without rewriting my whole source file to remove using namespace std
?
Qualify it to be global: ::bind(...)
(and make sure you have all the right headers included).
EDIT: (I got the idea from @Bo Persson's comment)
Another solid option is to change using namespace std;
to several using <thing>
like:
using std::cout;
using std::endl;
using std::string;
// etc.
This lets your old code compile and doesn't bring std::bind
into the global namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With