LibC ++ - name conflict for bind ()?

After an unexpected little hack, I was able to install libC ++ on my Linux server (since libstdC ++ is missing). Unfortunately, a bit of my existing code is now broken, due to functions with the same name.

As a rule, and as I need it, bind () refers to sockets. However, libC ++ came with its bind () function, which is basically this , but without a convenient namespace to separate them. According to Murphy’s law, the compiler tries to use the wrong function and spits out the error. NetBeans does not see any problem because it is really looking for the sys / socket.h file, as it is very good.

So, with both functions basically beyond my control, how can I tell the compiler (clang ++) that it should look in a specific header and nowhere else for that function?

+4
source share
2 answers

Firstly, this has nothing to do with Murphy, I would think: choosing a bind() template is probably only better. The std::bind() declaration is in the std , however, at least in the version of the header file I'm looking at. Is it possible that your source file contains a using directive? (in this case, you deserve all the pain you asked for)

If the directive is not used, a version other than the template should be better if the arguments match exactly . If this still does not help, you can create a forwarding function for the bind() function from <sys/socket.h> , say, avoid_conflict_bind() , which is the only function defined in the translation block, that is, it will only include <sys/socket.h> and not <functional> . Thus, for the bind() function, this function will not be selected, and you can use avoid_conflict_bind() .

+4
source

I had a conflict between bind() from <WinSock2.h> and std::bind() (I used using namespace std; )
I just added :: before calling the method and it will work! bind() => ::bind()

+6
source

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


All Articles