mercredi 26 juin 2019

using initializer list to initialize unordered_map

I have this class

class A {
    unordered_map<string, unordered_set<string>> n_;
  public:
    A(unordered_map<string, unordered_set<string>>& n) : n_{n} {}
};

And I want to be able to use the constructor with that syntax

int main() {
    A aC};
    return 0;
}

But in the way it's written now, I'm getting error

error: no matching function for call to ‘A::A(<brace-enclosed initializer list>)’ A aC};

How can it be fixed?

Thanks

Aucun commentaire:

Enregistrer un commentaire