我有一对的std ::串和Person指针测试地图std :: for_each是按值还是按引用传递?
class MyMap {
public:
void clear() {
std::for_each(people.begin(), people.end(),std::bind1st(std::mem_fun(&MyMap::remove), this));
}
void remove(std::pair<std::string, Person*> p) { delete p.second; }
private:
std::map<name, Person*> people;
};
我的问题是确实的for_each通过ref或值传递每个人对?这是值得使用我自己的,这是一个更清洁。
除此之外,如果我想要使用boost :: bind或std :: bind(C++ 11)而不是bind1st,我该怎么做?这个函数应该像struct继承std :: unary_function的operator()吗?
范围“的for_each通过ref或值传递每个人对”:通过在那里,如果你正在谈论的功能(第三个参数),这取决于如何?函数定义是。 –
看着目前的功能。 for_each不接受签名'void remove(std :: pair&p)'抱怨超载 –
abumusamq
为什么重要?你所有的删除功能都会删除Person。 – Wug