1
votes

I am using the following code

class test
{
public:
    test(std::vector<std::string> str)
    {
        auto a = str[0];
        a = "B";
    }
    test()
    {
    }
    const std::multimap<int,  std::multimap<int, test>> _var= {
        {0x01,  {
                    {
                        0x0f, std::vector<std::string>{"A", "B", "C", "D"}
                    }
        }
        }
    };
};

int main()
{
    test t;
    std::cout << "Done";
}

The above code builds fine however I get the bad access when I run it. I attached the call stack. Any suggestions why I am getting that error ? or how I can fix it ? Seems like its a constant loop.

enter image description here

1
Where is the error? The code complies fine for me. - cplusplusrat
Its not about compiling its a bad access now. Seems like its constant loop or something during initialization - Rajeshwar
try running the code - Rajeshwar
Tried it. Normal termination. What compiler are you using? - cplusplusrat
I am using clang. Xcode - Rajeshwar

1 Answers

3
votes

You have a case of infinite recursion, leading to stack overflow.

Create an instance of test -->
Initialize _var -->
Create an instance of test -->
Initialize _var -->

and so on.