I'm stuck. When trying to add a new element to the vector of strings inside a struct via the iterator I get this error about const
qualifier:
error: passing ‘const std::vector<std::__cxx11::basic_string<char> >’ as ‘this’ argument discards qualifiers [-fpermissive]
175 | p->children.push_back("New child");
The code:
typedef struct Concept_tree
{
string id;
string name;
std::vector<string> children;
bool operator==(const Concept_tree &ct2)
{
return (id == ct2.id);
}
Concept_tree() { };
Concept_tree(string id): id(id) { };
Concept_tree(string id, string term): id(id), name(term) { };
}
Concept_tree;
namespace std
{
template<>
struct hash<Concept_tree>
{
size_t operator()(const Concept_tree &ct) const
{
return std::hash<string>()(ct.id);
}
};
}
...
std::unordered_set<Concept_tree> ct_uset;
...
string test = "id00001";
auto p = ct_uset.find(test);
p->children.push_back("New child");
I understand the cause of the error but can't deduce its exact position. Is it that the constructors are implemented improperly? Could anyone help?