我已存储std::function
,这是std::bind
结果替换调用值,在列表中:性病::功能
typedef std::pair<int, std::function<void(HDC)>> myPair;
std::list<myPair> *paintJobs;
paintJobs = new std::list<myPair>();
我然后我补充这样的:
int id = 1;
int x = 0;
int y = 0;
int width = 100;
int height = 100;
int r = 255;
int g = 0;
int b = 0;
std::function<void(HDC)> func = std::bind(&Window::drawRect, this, std::placeholders::_1, x, y, width, height, r, g, b);
paintJobs->push_back(std::make_pair(id, func));
在我绘制方法我通过列表并调用所有函数,我已经添加了。这部分运作良好。
但现在,我想换例如色(R,G和B):
void changeColor(int id, int r, int g, int b) {
for(auto elem = paintJobs->begin(); elem != paintJobs->end(); ++elem) {
if(elem->first == id){
//change the 6th, 7th and 8th parameter of elem->second
}
}
}
我的另一个想法是插入一个新条目,并复制旧的价值观,但在其他问题:获取绑定值。
那么,我该如何替换参数的边界值或获取其他参数的值呢?
[OT]:'std :: list * paintJobs;'...不必要的指针,'std :: list paintJobs;'可能是你想要的。 –
Jarod42
这是一个更复杂的嵌入类,因此指针 –
如果你想改变“成员”,那么你应该创建一个仿函数并提供对它们的访问。然后你可以存储该函数而不是'std :: function'。 – NathanOliver