lundi 24 septembre 2018

Segmentation fault: 11 for Map Insert of tuple and tree pointer

map<tuple <string, int, int>, Tree*> parser(string sentence, map<string, vector<tuple<string, double>>> rules) {
    map< tuple<string, int, int>, Tree*> chart = {};
    string output = "";
    vector<string> words = sentenceIntoWords(sentence);

    for (int i = 0; i < words.size(); i++) {
        string word = words[i];
        if(rules.find(word) != rules.end()) {
            for(tuple<string,double>& PoS: rules[word]) {
                tuple<string,int,int> key = {get<0>(PoS), i, i};
                Tree* tree = new Tree(get<0>(PoS),i,i,word,nullptr,nullptr,get<1>(PoS));
                chart[key] = tree; //error occurs here
            }
        }
    }

Tree class

class Tree {
public:
    //constructor
    Tree (string phrase, int startPhrase, int endPhrase, string word, Tree* left, Tree* right, double prob):phrase(phrase),startPhrase(startPhrase), endPhrase(endPhrase), word(word), left(left), right(right), prob(prob){}

private:
    string phrase; // the part of speech
    int startPhrase; // indices starting word
    int endPhrase; //indices of ending word
    string word;
    Tree* left;
    Tree* right;
    double prob;
};

I get a Segmentation fault: 11 when I try to insert elements into the map chart where the key is a tuple and value is a tree pointer.

Aucun commentaire:

Enregistrer un commentaire