For loop crashing at the end

Here's my code

1
2
3
4
5
6
7
8
9
10
11
12
cout << "Input: " << history << endl;
map<char, int> result;

for (auto& v : children) 
    {
        cout << "Loop" << endl;
        cout << "Check: " << v.second << endl;
        result[v.first] = GetPoints(v.second, history);
        cout << "Don" << endl;
    }

    cout << "Done" << endl;


It prints:

Input 30
Loop
Check: 32
Don

Then it crashes.
- If it were inside the loop it'd print 'Loop' before crashing.
- If it's outside it would print 'Done' before crashing.

Since it prints neither I can only assume the bug has to do with the actual for loop causing the crash.

How is this even possible?
Last edited on
The cause of the problem isn't necessarily where the crash is happening.

To find the problem you might want to use a debugger.

You can of course post the complete code here but if it's a big program you should probably try removing everything that is not necessary for the crash to happen first. In the process of doing so you are likely to find the problem yourself. If you still haven't found the problem at least you have made it easier for us to help you. Just make sure the program still compiles and crashes before posting the code.
Last edited on
I tried debugging, it gives Segmentation error at line
cout << "Check: " << v.second << endl;

Any idea what it means? v.second exist and will be printed before it crash in non-debug mode.
In my Header file I create the map:
1
2
3
4
class Layer
{
    private:
        map<char, string> children;


Is this an issue?
Because I create two Layer class objects and it's only the second one that causes this issue when run.
Turns out the layer two was saved given by parameter (not as pointer) and layer 1 saved the pointer to the (temporary) parameter. That is why locating it later was an issue.
Topic archived. No new replies allowed.