mardi 26 juillet 2016

How to fix a Core Dumped error when it's after the function correctly executes?

I have a C++ code that resembles this:

class Apple {
 ...
}

vector<T> foo(Apple<T> *apple) {
    static unordered_map< Apple<T>*, vector<T> > table;

    vector<T> v, u, w, x;
    if(existsInMap()){
        getFromMapAndReturn();
    }
    else {
        u = foo(apple)
        v = findAnswer(u, v, w, x);
    }

    table[apple] = v;
    print(v);
    return v;
}

void bar() {
    vector<T> v = foo(some_apple);
    print(v);
}

I compile it using g++ 5.4.0 on Cygwin:

g++ apple.cpp -std=c++11

The problem is that the after the recursive function foo() completes, the last print gives me the correct answer.

But after that I get this error: Aborted (core dumped)

And the print in bar() doesn't execute.

This is baffling because my logic seems to be correct. What is causing this?

Aucun commentaire:

Enregistrer un commentaire