1

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

9
  • Where is the error? The code complies fine for me. Commented Apr 24, 2019 at 21:21
  • Its not about compiling its a bad access now. Seems like its constant loop or something during initialization Commented Apr 24, 2019 at 21:22
  • try running the code Commented Apr 24, 2019 at 21:23
  • Tried it. Normal termination. What compiler are you using? Commented Apr 24, 2019 at 21:23
  • I am using clang. Xcode Commented Apr 24, 2019 at 21:26

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.