Boost logo

Boost Users :

Subject: [Boost-users] boost bind() error for creating thread
From: Jack Bryan (dtustudy68_at_[hidden])
Date: 2011-09-05 18:38:53


Hi,
I using boost::bind() to create thread. But, I got errors at:
threadGroup.create_thread(boost::bind(&lab1::Server::Run, server));
Any help is really appreciated.
Code is as follows: ---------------------------------------------
class Server {public: // The constructor takes a port number and prepares to receive HTTP // requests from clients on that port. explicit Server(int port);
  // Closes the connection. ~Server();
  // void Run(); //Server(Server&);private: // 'listening' socket used to establish HTTP connections int listen_fd_;
  // Non-copyable, non-assignable Server(Server&); Server& operator=(Server&);};

int main(int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: lab1 <port>" << std::endl; return 1; }
// Convert the port from a string to an integer. int port_number; std::istringstream port_stream(argv[1]); // argv[1] is port number, port_stream >> port_number;
  // Convert the thread number from a string to an integer. int thread_number; std::istringstream thread_stream(argv[2]); // argv[1] is port number, thread_stream >> thread_number; lab1::Server server(port_number);
boost::thread_group threadGroup;
for(int i=0;i<thread_number;i++) {
     threadGroup.create_thread(boost::bind(&lab1::Server::Run, server)); }threadGroup.join_all(); return 0;}
error: no matching function for call to âboost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >::bind_t(boost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >)â

/bind.hpp:865: note: candidates are: boost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >::bind_t(boost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >&)
lab2.cpp:241: error: initializing argument 1 of âboost::thread* boost::thread_group::create_thread(F) [with F = boost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >]â

bind_mf_cc.hpp: In function âboost::_bi::bind_t<R, boost::_mfi::mf0<R, T>, typename boost::_bi::list_av_1<A1>::type> boost::bind(R (T::*)(), A1) [with R = void, T = lab1::Server, A1 = lab1::Server]â
error: initializing argument 1 of âboost::thread* boost::thread_group::create_thread(F) [with F = boost::_bi::bind_t<void, boost::_mfi::mf0<void, lab1::Server>, boost::_bi::list1<boost::_bi::value<lab1::Server> > >]â
instantiated from herebind_mf_cc.hpp:24: error: no matching function for call to âboost::_bi::list1<boost::_bi::value<lab1::Server> >::list1(boost::_bi::list1<boost::_bi::value<lab1::Server> >)â

                                               



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net