有人可以解释或帮助我为什么这不起作用吗?C++中的Lambda表达式std :: copy_if
std::vector<std::shared_ptr<Publication> > Bibliography::givePubWithIFHigherThan(float value) const
{
Publication *p;
std::vector<std::shared_ptr<Publication>> highIFPubs(publications);
auto checkIF = std::mem_fun(p->IFHigherThan(value));
auto last = std::copy_if(publications.begin(), publications.end, highIFPubs.begin(),
[=] (std::shared_ptr<Publication> p)
{
return checkIF(*p, value);
});
return highIFPubs;
}
class Publication
{
public:
Publication(std::string aTitle, int aYear, std::string anID);
virtual bool IFHigherThan(float value) const {return false;};
private:
};
class Paper : public Publication
{
public:
Paper(std::string aTitle, int aYear, std::string aJournal, float aImpactFactor);
bool IFHigherThan(float value) const {return value < impactFactor;};
private:
};
目前,我得到这个错误,
no matching function for call to 'mem_fun(bool)' auto checkIF = std::mem_fun(p->IFHigherThan(value)); ^
这是因为你正在调用IFHigherThan函数,而不是传递指针。 –
但是p是一个指针吧? – user4390280
是的,'p'是一个指针,但是'p-> IFHigherThan(value)'是一个函数调用,导致一个'bool'。 –