Errors on operations of datatype map of sets of classes

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>

using namespace std;

class State;
typedef map<char, set<State>> symbol2States;

vector<string> split_string(string);

char Epsilon = 'e';
int c = 0;

string idGenerator() {
    return to_string(c++);
}

class State {
    public:
        string id;
        symbol2States trans;
        bool accepting;

        State(bool accepting=false) {
            this->accepting = accepting;
            this->id = idGenerator();
        }

        void addTransitionForSymbol(char symbol, State& s)  {
            if (trans.find(symbol) == trans.end()) {
                set<State> newSet;
                trans.insert({symbol, newSet});
            } else {
                trans[symbol].insert(s);
            }
        }

        set<State> getTransitionToSymbol(char symbol) const {
            return *(trans.find(symbol));
        }

        bool test(string str, set<State>& visited) const {
            if (visited.find(this) != visited.end()) {
                return false;
            }

            //....
        }

        set<State> getEpsilonClosure() {

            set<State> eplisonStates = getTransitionToSymbol(Epsilon);
            set<State> closure (eplisonStates.begin(), eplisonStates.end());
            closure.insert(*this);

            return closure;
        }
};

```

Some errors i got :

main.cpp: In member function ‘std::set<State> State::getTransitionToSymbol(char) const’:
main.cpp:39:20: error: could not convert ‘((const State*)this)->State::trans.std::map<_Key, _Tp, _Compare, _Alloc>::find, std::less, std::allocator > > >(symbol).std::_Rb_tree_const_iterator<_Tp>::operator* > >()’ from ‘const std::pair >’ to ‘std::set’
return *(trans.find(symbol));
^~~~~~~~~~~~~~~~~~~~~
main.cpp: At global scope:


Last edited on
std::map::find() returns an iterator to the map element. The element is a std::pair, but you're tring to return it as if it were the value part of a key-value pair.

The map.find return a std::pair<char, set<State>> but getTransitionToSymbol should return a
set<State>
Topic archived. No new replies allowed.