Add a pair to a std::map that has a const value

86 Views Asked by At

I need to update this map to include one more key-pair. The map is const std::map<char, std::shared_ptr<const TrieNode>> children_.

The const seems to block any method that is tried. Attempted code:

  1. children_[]
  2. children_.insert()
  3. children_ = /* newly created map */

Why can I not override the existing map?

Example:

  current_node->children_['c'] = std::make_shared<TrieNode>(TrieNode());

Getting errors:

No viable overloaded operator[] for type 'const std::map<char, std::shared_ptr<const TrieNode>>'clang(ovl_no_viable_subscript)
stl_map.h(512, 7): Candidate function not viable: 'this' argument has type 'const std::map<char, std::shared_ptr<const TrieNode>>', but method is not marked const
stl_map.h(492, 7): Candidate function not viable: 'this' argument has type 'const std::map<char, std::shared_ptr<const TrieNode>>', but method is not marked const
0

There are 0 best solutions below