以下のコードスニペット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());
}
SNIPPET 2(コンパイルエラー)
ServiceRegistrarAPI.cpp:355:72: error: passing ‘const EndPointAddr’ as ‘this’ argument of ‘EndPointTipcAddr& EndPointAddr::getTipcAddress()’ discards qualifiers [- fpermissive]
CODE SNIPPET 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;
}