Search code examples
c++boostboost-bind

How to understand this boost::bind sentence? It's different from what I searched on Internet


  DepthFilter::callback_t depth_filter_cb = boost::bind(&MapPointCandidates::newCandidatePoint, &map_.point_candidates_, _1, _2);

And the binded function defines as this:

void MapPointCandidates::newCandidatePoint(Point* point, double depth_sigma2)

According to the bind sentence, this function should take 3 params. First one is &map_.point_candidates_, then 2nd and 3rd catch other params.

But actually, the defined function only takes 2 params. And their types are not consistent with the bind sentence.


Solution

  • The first parameter is the receiver (this) for the member function. The resulting bind object only requires the member function parameters to be called, not the receiver as well.

    It can then be passed to something which accepts something function-like but doesn't have any understanding of calling a member function of an object - for example, something in std::algorithm.