How to distinguish bind () in sys / sockets.h and std :: bind?

I am using g ++ 4.6.0 to compile C ++ code that was successfully compiled in earlier versions.

if ( bind(iControl, (struct sockaddr *) &sa, sizeof(sa)) == -1) throw runtime_error ("bind"); 

where iControl is the socket and sa is the 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:

and then about half of the possible candidates.

It seems to mix the binding function in sys/sockets.h with std :: bind in functional . How to fix these two issues without rewriting the entire source file to remove using namespace std ?

+6
source share
1 answer

Confirm that it is global: ::bind(...) (and make sure you include all the correct headers).

EDIT: (I got the idea from a comment by @Bo Persson) Another solid option is to change using namespace std; on a few using <thing> like:

 using std::cout; using std::endl; using std::string; // etc. 

This allows you to compile old code and not transfer std::bind to the global namespace.

+18
source

Source: https://habr.com/ru/post/891841/