lundi 27 juillet 2020

binary '==': 'tag' does not define this operator or a conversion to a type acceptable to the predefined operator

I am literally new with c++. Just learning. can anyone help me with this?

typedef pair<string, string> attr;
struct tag {
   int id;
   int parentIndex;
   string identifier;
   vector<attr> attributes;
};

int main() {
    vector<tag> ctags{ tag{1,1, "test"} };
    string query{"test"};
    auto utag = find(ctags.begin(), ctags.end(), [query](tag t) { return t.identifier == query; });
}

whenever I am trying to run that, I am getting the above error. So tried

bool operator==(tag& rhs)
{
    return this->identifier == rhs.identifier;
}

bool operator==(string& rhs)
{
    return this->identifier == rhs;
}

Nothing is working for, anyone??

Aucun commentaire:

Enregistrer un commentaire