map-operator [] Operanden
Hallo an alle ich habe Folgendes in einer member-Funktion
int tt = 6;
vector<set<int>>& temp = m_egressCandidatesByDestAndOtMode[tt];
set<int>& egressCandidateStops = temp.at(dest);
und die folgende Deklaration der member-variable
map<int, vector<set<int>>> m_egressCandidatesByDestAndOtMode;
Jedoch bekomme ich einen Fehler beim kompilieren (Intel Compiler 11.0)
1>C:\projects\svn\bdk\Source\ZenithAssignment\src\Iteration\PtBranchAndBoundIterationOriginRunner.cpp(85): error: no operator "[]" matches these operands
1> operand types are: const std::map<int, std::vector<std::set<int, std::less<int>, std::allocator<int>>, std::allocator<std::set<int, std::less<int>, std::allocator<int>>>>, std::less<int>, std::allocator<std::pair<const int, std::vector<std::set<int, std::less<int>, std::allocator<int>>, std::allocator<std::set<int, std::less<int>, std::allocator<int>>>>>>> [ const int ]
1> vector<set<int>>& temp = m_egressCandidatesByDestAndOtMode[tt];
1> ^
Weiß ich es ja etwas dumm, aber ich kann nicht sehen, was ich falsch gemacht habe.
UPDATE ich rufe diese aus einer const-member-Funktion, die ist, warum die member-variable des Typs const, so dachte ich, dass so etwas wie das folgende Problem beheben sollte:
int dest = 0, tt = 6;
const set<int>& egressCandidateStops = m_egressCandidatesByDestAndOtMode[tt].at(dest);
Aber keine Würfel... immer noch der gleiche Fehler.
- Die Antwort von Potatoswatter korrekt ist. Um zu vermeiden, Ihr problem, müssen Sie Verwendung finden.
Du musst angemeldet sein, um einen Kommentar abzugeben.
map::operator[]
funktioniert nicht mit einerconst map
.Ich beantwortet vor ein paar Tagen.
std::map::at
jetzt.Den Prototyp für
[]
istd.h. eine nicht-const-Betrieb, so kann man es nicht nennen, auf ein Mitglied aus einer const-Memberfunktion .
Könnten Sie ändern Sie den code: