在下面的第一個代碼片段中,我試圖從一個成員函數中的一個向量中移除一個元素,該元素基於一個靜態條件函數饋入std :: remove函數。然後,我收到了第二個片段中顯示的大量模板錯誤。你能告訴我我錯過了什麼嗎?從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(
mVipAddressList.begin(),
mVipAddressList.end(),
RemoveCond::condition);
mVipAddressList.erase(last, mVipAddressList.end());
}
內容片段2(編譯輸出)
/usr/include/c++/4.7/bits/random.h:4845:5: note: template<class _IntType> bool std::operator==(const std::discrete_distribution<_IntType>&, const std::discrete_distribution<_IntType>&)
/usr/include/c++/4.7/bits/random.h:4845:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
from Entity.hpp:12:
/usr/include/c++/4.7/bits/stl_algo.h:174:4: note: ‘ECLBCP::VipAddressEntity’ is not derived from ‘const std::discrete_distribution<_IntType>’
In file included from /usr/include/c++/4.7/random:50:0,
from /usr/include/c++/4.7/bits/stl_algo.h:67,
from /usr/include/c++/4.7/algorithm:63,
from Entity.hpp:12:
/usr/include/c++/4.7/bits/random.h:4613:5: note: template<class _RealType> bool std::operator==(const std::extreme_value_distribution<_RealType>&, const std::extreme_value_distribution<_RealType>&)
/usr/include/c++/4.7/bits/random.h:4613:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
from Entity.hpp:12:
/usr/include/c++/4.7/bits/stl_algo.h:174:4: note: ‘ECLBCP::VipAddressEntity’ is not derived from ‘const std::extreme_value_distribution<_RealType>’
這只是一些註釋部分的錯誤信息,真正的錯誤是缺少的。 – PlasmaHH 2013-02-22 13:15:43
據我所知,你不能在這裏使用RemoveCond :: condition作爲模板參數。看看http://stackoverflow.com/a/7627218/767543其中「然而這是不允許的,f不能傳遞給C++ 03中的模板函數。」陳述。 雖然我可能錯了 – 2013-02-22 13:17:52
我得到了很多錯誤信息,無法放入終端的緩衝區中...... – 2013-02-22 13:18:57