结构中的动态数组长度

Dynamic array length in struct

我想做的是创建一个结构,其中包含另一个结构的数组,我想在运行时设置数组的大小。有什么办法吗? 结构如下:

struct MyStruct
{
  AnotherStruct list[];
  int key;
  bool isLeaf;
}

一种方法是:

#include <vector>

struct MyStruct
{
    std::vector<AnotherStruct> list;
    int key;
    bool isLeaf;
};

如果您是向量的新手,您可以在任何 C++ 参考资料中阅读有关如何使用它们的信息。