boost::bind problem

can someone explain this to me, the docs are completely useless.


i have a server class that uses boost.bind like so:

its_acceptor.async_accept(its_socket, boost::bind(&Server::Handle_Accept, this, boost::asio::placeholders::error));

which works perfect. however i have to pass this to the boost bind... why do i have to do that?

Handle_Accept doesn't use a this object (a Server class object) for a damn thing??

im also trying to do the same thing in my main() but i can't pass this in main() so it won't work.

since i don't know why im passing this i can't really think of a solution on my own.

can someone please explain? the docs on boost.bind are completely usless. they suck. every other thing i use from boost has great docs, but its like the bind docs aren't even talking about the same thing??..
If Server::Handle_Accept() is not a static member function then yes, it does take a Server as a parameter. All non-static member functions take an implicit parameter, which is a pointer to an object of the class (e.g. T::f() would take a T *). This is the this parameter.
You can't pass this from main() because main() is not a member function, so was never passed a this parameter. You need to pass a pointer to an existing Server object, if you have one.
oh yea. actually i think i thought that a while ago but forgot i thought of it.. lol.

anyway i just realized i wasn't clear about my problem in main.
i wasn't using a Server object at all, instead i was doing something like this..

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
	boost::asio::io_service io_service;

	boost::asio::ip::tcp::acceptor acceptor(io_service);
	boost::asio::ip::tcp::socket socket(io_service, boost::asio::ip::tcp::v4());

	acceptor.async_accept(socket, boost::bind(handler, I_NEED_SOMETHING_HER_BUT_WHAT, arg1, arg2, blah));

	io_service.run();

	return 0;
}



EDIT:

atm nvm, i think i figured it out. ill post back if i need help. thanks :)
Last edited on
Topic archived. No new replies allowed.