In code snippet 1 below, mKnownSRList is defined as follows:
std::vector<EndPointAddr*> mKnownSRList;
I am getting a compilation error shown in code snippet 2. Can you tell me what's wrong with this code please? The content of the getTipcAddress() and compareTo functions are shown in code snippet 3 and 4 below.
CODE SNIPPET 1 (Compilation error is marked)
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 (Compilation Error)
ServiceRegistrarAPI.cpp:355:72: error: passing ‘const EndPointAddr’ as ‘this’ argument of ‘EndPointTipcAddr& EndPointAddr::getTipcAddress()’ discards qualifiers [- fpermissive]
CODE SNIPPET 3 (getTipcAddress function)
EndPointTipcAddr & getTipcAddress() { return mTipcAddress; }
CODE NIPPET 4 (compareTo function)
bool
EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs)
{
if( (mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()) )
{
return true;
}
return false;
}