在下面的代码片段1中,mKnownSRList被定义如下:
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());
}
片段 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; }
代码片段4 (compareTo函数)
bool
EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs)
{
if( (mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()) )
{
return true;
}
return false;
}