如何拆分功能:绑定

how to split function: bind

本文关键字:功能 绑定 拆分 何拆分      更新时间:2023-10-16

我需要在嵌入的posix中编译 bind函数,并且不能使用 boost::bindstd::bind

所以我想拆分功能: threadReducer.reduce(boost::bind(&DepthMap::observeDepthRow, this, _1, _2, _3), 3, height-3, 10);

函数观察到epthrow:
void DepthMap::observeDepthRow(int yMin, int yMax, RunningStats* stats)
功能降低:
void IndexThread::reduce(boost::function<void(int,int,RunningStats*)> callPerIndex, int first, int end, int stepSize = 0)

plz,帮助我拆分功能,我不擅长C

如果您不能使用Boost或C 11 ..在这种情况下,您可以尝试这样做:

void IndexThread::reduce(void(*function)(int,int,RunningStats*), int first, int end, int stepSize = 0)

使您的observeDepthRow static

static void DepthMap::observeDepthRow(int yMin, int yMax, RunningStats* stats)

然后您可以这样称呼:

threadReducer.reduce(observeDepthRow, 3, height-3, 10);

尽管在这种情况下,如果您不希望,则必须制作方法static,因此请务必查看。