views:

104

answers:

1

I'm fairly new to C++, and I'm likely in over my head, but that's the way it goes.

I'm working with a fairly large Win32 C++ project that uses Winsock for its network communications. I'm in the process of trying to convert a bunch of its thread management over to boost, but once I added the references to the boost libraries and what-not, I'm getting about 30 errors on this particular line of code:

bind(mLocalSocketFd, (struct sockaddr *) &localServerAddress, sizeof(localServerAddress));

The errors include things like:

error C2602: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' is not a member of a base class of 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>'
error C2868: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' : illegal syntax for using-declaration; expected qualified-name
error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::tr1::_Bind_fty<_Fty,_Ret,_BindN>' 
error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::tr1::_Bind_fty<_Fty,_Ret,_BindN>'

I presume that somehow I've managed to tell this particular file ("NetServer.cpp") to use the boost version of bind(), but for the life of me, I can't figure out where that's happening. The only portion of boost that I'm using is the boost/thread.hpp, and I'm not doing any namespace using's anywhere in NetServer.cpp or in the header files that it links to.

Any suggestions as to what I'm doing wrong, or how to troubleshoot it? It's obviously some stupid newbie thing, but I can't figure it out.

A: 

There's a Boost function called bind() which is a totally different thing from Winsock's bind(). You have two options if you need both functions available in a given module:

  1. Don't say "using namespace boost". Explicitly qualify uses of Boost in your code. I prefer this option since Boost is a third-party library and its short names may conflict both with other third-party libraries and with future versions of C++ that adopt Boost features. Occasionally I will say "using namespace boost" within a single function if it contains several uses of Boost.

  2. Explicitly qualify the use of the global Winsock bind():

    ::bind(mLocalSocketFd, ...

Warren Young
I wasn't "using namespace boost;" anywhere in the header hierarchy that I could find, which is what was confusing me. And I'm still not sure why it's trying to use the boost namespace in that particular file. But I wasn't aware that :: acted as a global namespace qualifier. Adding that solved the problem. Thanks.
Ken Smith