在代碼片段低於1,mKnownSRList定義如下:常量XX丟棄預選賽[ - fpermissive]
std::vector<EndPointAddr*> mKnownSRList;
我得到的代碼片段所示編譯錯誤2.你能告訴我有什麼不對的代碼請? getTipcAddress()和compareTo函數的內容顯示在下面的代碼片段3和4中。
代碼段1(編譯錯誤標記)
void
ServiceRegistrarAPI::removeKnownSR(EndPointAddr & srEndPointAddr)
{
auto last =
std::remove_if(mKnownSRList.begin(),
mKnownSRList.end(),
[srEndPointAddr](EndPointAddr* o)
{
//LINE 355 is the following
EndPointTipcAddr myTipcAddress = srEndPointAddr.getTipcAddress();
EndPointTipcAddr otherTipcAddress = o->getTipcAddress();
return (myTipcAddress.compareTo(otherTipcAddress));
});
if(*last != nullptr)
{
delete *last;
}
mKnownSRList.erase(last, mKnownSRList.end());
}
SNIPPET 2(編譯錯誤)
ServiceRegistrarAPI.cpp:355:72: error: passing ‘const EndPointAddr’ as ‘this’ argument of ‘EndPointTipcAddr& EndPointAddr::getTipcAddress()’ discards qualifiers [- fpermissive]
代碼段3(getTipcAddress功能)
EndPointTipcAddr & getTipcAddress() { return mTipcAddress; }
CODE NIPPET 4(的compareTo功能)
bool
EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs)
{
if((mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()))
{
return true;
}
return false;
}
沒有詳細考慮過這個,但我相信[這將是相關的( http://stackoverflow.com/questions/2835626/c0x-lambda-capture-by-value-always-const)。 – BoBTFish 2013-03-25 15:18:57