在代码片段低于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