In the code snippet below, mKnownSRList is defined as follows:
std::vector<EndPointAddr*> mKnownSRList;
I get the compilation error shown in code snippet 2. Can you tell me what is wrong with this code, please? The contents of the getTipcAddress () and compareTo functions are shown in code snippets 3 and 4. below.
CODE SNIPPET 1 (compilation error noted)
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; }
NIPPET 4 CODE (compareTo function)
bool EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs) { if( (mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()) ) { return true; } return false; }
source share