'sTD :: String getAttribute (std :: string)'의 'this'인수로 'const 링크'를 전달합니다.
문제
NS-3 API의 일부로 홀수 오류가 발생합니다.다음은 내 오류 메시지입니다.
error: passing ‘const ns3::TopologyReader::Link’ as ‘this’ argument of ‘std::string ns3::TopologyReader::Link::GetAttribute(std::string)’ discards qualifiers
.
여기에 문제를 일으키는 코드가 있습니다.
TopologyReader::ConstLinksIterator iter;
int num = 0;
for (iter = topologyReader->LinksBegin (); iter != topologyReader->LinksEnd(); iter++, num++)
{
std::istringstream fromName(iter->GetFromNodeName ());
std::istringstream toName (iter->GetToNodeName ());
iter->GetToNodeName();
std::string w = "Weight";
std::string weightAttr = (iter)->GetAttribute(w); // <- error
/* snip */
}
.
해결책
Your analysis is correct. The obvious fix is to make GetAttribute
be a const function. Its name suggests it should be const. It might not be in your power to change that code, though.
The alternative is to find some way of getting a non-const object to call the function on. Maybe you could declare iter
as a LinksIterator
instead of a ConstLinksIterator
.
As a last resort, you could try using const_cast
to tell the compiler that it's really safe to call a non-const method on a supposedly const object.
제휴하지 않습니다 StackOverflow