c++11uniform-initialization

Initializing a vector<std::string> in uniform initialization


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


Solution

  • 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.