【发布时间】:2013-03-25 15:16:17
【问题描述】:
在下面的代码sn-p 1中,mKnownSRList定义如下:
std::vector<EndPointAddr*> mKnownSRList;
我收到代码 sn-p 2 中显示的编译错误。您能告诉我这段代码有什么问题吗? getTipcAddress() 和 compareTo 函数的内容如下面的代码 sn-p 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]
代码片段 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;
}
【问题讨论】:
-
没有详细考虑过这个,但我相信this will be relevant。