首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何拆分函数:绑定

如何拆分函数:绑定
EN

Stack Overflow用户
提问于 2016-11-23 20:47:17
回答 1查看 46关注 0票数 0

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

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

其中函数observeDepthRow:

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

和函数reduce:

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

请帮我拆分函数,我不擅长C++

EN

回答 1

Stack Overflow用户

发布于 2016-11-24 10:00:37

如果您不能使用boost或c++11 ..在这种情况下,您可以像这样尝试:

代码语言:javascript
复制
void IndexThread::reduce(void(*function)(int,int,RunningStats*), int first, int end, int stepSize = 0)

让你的observeDepthRow static

代码语言:javascript
复制
static void DepthMap::observeDepthRow(int yMin, int yMax, RunningStats* stats)

然后你可以这样叫它:

代码语言:javascript
复制
threadReducer.reduce(observeDepthRow, 3, height-3, 10);

虽然在这种情况下,您必须将方法设置为static,但如果您不希望这样做,请查看this

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40764988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档