black sheep
black sheep

Reputation: 399

Why do I get an error "using temporary as lvalue"

I cannot understand why I am getting an "using temporary as lvalue" error.

void setEdgeLengths(
    const Koala::AssocArray <
        koalaGraph::PEdge, 
        Koala::DijkstraHeap::EdgeLabs<int>
    > &edgeMap, 
    const std::vector<koalaGraph::PEdge> &E) 
{
   int edgeLength = 1;
   for (const auto& e : E) {
      edgeMap[e].length = edgeLength;
   }
}

The variable edgeLength is not temporary.

Upvotes: 0

Views: 2705

Answers (1)

cfillion
cfillion

Reputation: 1397

From the documentation found here (thanks to Google):

Elem Koala::AssocArray<Klucz, Elem, Container>::operator[](Klucz v) const

This returns a temporary value (the non-const overload returns a reference but inserts a new item if the key doesn't exist). Try using valPtr instead.

edgeMap.valPtr(e)->length = edgeLength;

Upvotes: 1

Related Questions