在下面的代码片段 1 中,mKnownSRList 定义如下:
std::vector<EndPointAddr*> mKnownSRList;
我收到代码片段 2 中显示的编译错误。您能告诉我这段代码有什么问题吗?getTipcAddress() 和 compareTo 函数的内容如下面的代码片段 3 和 4 所示。
CODE SNIPPET 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; }
CODE NIPPET 4(比较功能)
bool
EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs)
{
if( (mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()) )
{
return true;
}
return false;
}