-1

I can't figure out why I'm getting this error yet the same class worked perfectly under VS15 now I'm using VS12, it's a simple Winsock2 implementation,

int Net::createServer(int port, int protocol) 
{
    int status;

    // ----- Initialize network stuff -----
    status = initialize(port, protocol);
    if (status != NET_OK)
        return status;

    localAddr.sin_addr.s_addr = htonl(INADDR_ANY);    // listen on all addresses

    // bind socket
    if (bind(sock, (SOCKADDR *)&localAddr, sizeof(localAddr)) == SOCKET_ERROR)
    {
        status = WSAGetLastError();          // get detailed error
        return ((status << 16) + NET_BIND_FAILED);
    }
    bound = true;
    mode = SERVER;

    return NET_OK;
}

the problem comes from here

if (bind(sock, (SOCKADDR *)&localAddr, sizeof(localAddr)) == SOCKET_ERROR)

Console Logs :

error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>' (or there is no acceptable conversion)
1>          with
1>          [
1>              _Forced=false,
1>              _Ret=void,
1>              _Fun=SOCKET &,
1>              _V0_t=SOCKADDR *,
1>              _V1_t=size_t,
1>              _V2_t=std::_Nil,
1>              _V3_t=std::_Nil,
1>              _V4_t=std::_Nil,
1>              _V5_t=std::_Nil,
1>              <unnamed-symbol>=std::_Nil
1>          ]
Eddy
  • 109
  • 1
  • 9
  • 2
    Your code using _Winsock_ worked under Ubuntu? Impressive... – Lightness Races in Orbit Jan 25 '16 at 14:35
  • Yes Yes it was a mistake – Eddy Jan 25 '16 at 14:36
  • 1
    Please post a [mcve] instead of such a large code dump. Also, your include guard is illegal: https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier – Baum mit Augen Jan 25 '16 at 14:39
  • What is the signature of `bind()`? – NathanOliver Jan 25 '16 at 14:40
  • std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,> – Eddy Jan 25 '16 at 14:42
  • @BaummitAugen I can't reproduce my problem with a minimal code , my question have allready a minimal exemple and I've provided the code that reproduce to exacte same issue – Eddy Jan 25 '16 at 14:46
  • @Eddy This is _not_ a minimal example. 90% of the code has nothing to do with your problem. That said, your code is calling [`std::bind`](http://en.cppreference.com/w/cpp/utility/functional/bind), probably because of a `using namespace std` somewhere. I guess you're running into a naming collision. – mindriot Jan 25 '16 at 14:52
  • @Eddy You certainly do not need dozens of namespace scoped variables, long comments and all those member variables to demonstrate such a compilation error, and you most likely do not need the full implementation for every member function either. Go show some effort. – Baum mit Augen Jan 25 '16 at 14:53
  • Most likely, you are `using namespace std` (the terrible thing to do!) and now BSD sockets `bind` is conflicting with `std::bind`. Stop using standard namespace once and for all. – SergeyA Jan 25 '16 at 14:54
  • ok I'm sorry @BaummitAugen – Eddy Jan 25 '16 at 14:59

1 Answers1

6

(A bit of leap of faith here, but I am pretty sure I got it right). The reason for the error is that you have a using namespace std statement somewhere in your program (the terrible thing to do!) and now the BSD socket bind() function is conflicting with the STL std::bind function.

Stop using using namespace std statements once and for all, and the problem will go away. Otherwise, you have to qualify which namespace to pull bind() from, in this case the global namespace:

if (::bind(sock, (SOCKADDR *)&localAddr, sizeof(localAddr)) == SOCKET_ERROR)
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
SergeyA
  • 61,605
  • 5
  • 78
  • 137