二维结构体数组部分初始化问题
程序代码:
class AA { struct Cell { int x; int y; String value; }; struct Cell m_cell[3][20]; }
在AA类里定义struct Cell类型的结构体,如何在m_cell[3][20]初始化的时候对结构体里部分数据进行赋值,不是那种一个变量一个变量赋值的方式。m_cell[3][20]为AA类中的全局变量。
class Foo { struct C { int x, y; std::string value; }; C m_cell[3][20]; private: void m_cell_init(); public: Foo() : m_cell {} { this->m_cell_init(); } };
class Foo { struct C { int x, y; std::string value; C(int, int, const std::string &); }; vector<vector<C>> m_cell; public: Foo() : m_cell { {C(1, 1, "第一维度")}, {C(2, 1, "第二维度")}, {C(2, 2, "第二维度")}, {} //第三维度为空 } {} };
class Foo { struct C { int x, y; std::string value; C(int, int, const std::string &); }; vector<vector<C>> m_cell; public: Foo() : m_cell { {C(0, 0, "第一维度")}, {C(0, 1, "第一维度")}, {C(0, 2, "第一维度")}, {C(0, 3, "第一维度")}, {C(1, 0, "第二维度")}, {C(1, 1, "第二维度")}, {C(2, 0, "第三维度"), {C(2, 1, "第三维度"), } {} };