使用大括号括起初始化列表初始化struct vector

Gin*_*as_ 10 c++ struct vector initializer-list c++11

我初始化这样的普通类型向量:

vector<float> data = {0.0f, 0.0f};
Run Code Online (Sandbox Code Playgroud)

但是当我使用结构而不是普通类型时

struct Vertex
{
    float position[3];
    float color[4];
};
vector<Vertex> data = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}};
Run Code Online (Sandbox Code Playgroud)

我收到错误could not convert '{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}}' from '<brace-enclosed initializer list>' to 'std::vector<Vertex>'.这有什么问题?

hmj*_*mjd 17

{}缺少一组:

std::vector<Vertex> data =
{ // for the vector
    { // for a Vertex
        {0.0f, 0.0f, 0.0f},      // for array 'position'
        {0.0f, 0.0f, 0.0f, 0.0f} // for array 'color'
    },
    {
        {0.0f, 0.0f, 0.0f},
        {0.0f, 0.0f, 0.0f, 0.0f}
    }
};
Run Code Online (Sandbox Code Playgroud)