在下面的第一个代码片段中,我试图从一个成员函数中的一个向量中移除一个元素,该元素基于一个静态条件函数馈入std :: remove_if函数。我的问题在于,在条件函数中无法访问removeVipAddress方法中的输入参数uuid。基于名为uuid的输入参数,您认为我应该在这里执行什么操作以从矢量中移除项目?谢谢。注:这是一个后续问题Removing an item from an std:: vector先前解释后续行动:从std :: vector中删除一个项目
SNIPPET 1(CODE)
void removeVipAddress(std::string &uuid)
{
struct RemoveCond
{
static bool condition(const VipAddressEntity & o)
{
return o.getUUID() == uuid;
}
};
std::vector<VipAddressEntity>::iterator last =
std::remove_if(
mVipAddressList.begin(),
mVipAddressList.end(),
RemoveCond::condition);
mVipAddressList.erase(last, mVipAddressList.end());
}
内容片段2(编译输出)
$ g++ -g -c -std=c++11 -Wall Entity.hpp
Entity.hpp: In static member function ‘static bool ECLBCP::VipAddressSet::removeVipAddress(std::string&)::RemoveCond::condition(const ECLBCP::VipAddressEntity&)’:
Entity.hpp:203:32: error: use of parameter from containing function
Entity.hpp:197:7: error: ‘std::string& uuid’ declared here