Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

C++11 - Initializer list of the aggregate does not work



  • Hello guys, I have a structure and test function:
    @
    struct Structure
    {
    QString s;
    QString a;
    };
    void testFunc(std::initializer_list<Structure> list)
    {
    // ...
    }
    @
    When I call it:
    @
    testFunc({"a", "b"});
    @

    MinGW yells:
    @
    error: could not convert '{"a", "b"}' from '<brace-enclosed initializer list>' to 'std::initializer_list<Structure>'.
    @

    What am I missing?



  • Can't say now, is this illegal in C++11 or just gcc flaw, but it certainly wants another pair of braces enclosing the first one, since it considers {"a", "b"} a single Structure literal, not the whole list.


Log in to reply