在下面的第一個代碼片段中,我試圖從一個成員函數中的一個向量中移除一個元素,該元素基於一個靜態條件函數饋入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