3 C++的3维矢量

发布于 2025-02-04 07:42:08 字数 283 浏览 0 评论 0原文

我想存储一个对象向量的节点和集合子集。 因此,我想实现一个3 d向量,其中第一个维度的大小#nodes = n,第二维为2^| set | = m。最后一个维度不应该具有固定的大小,因为我想在程序中附加新对象。

vector< vector < vector<Object>>> Vector3d( n , ( m, ( ( ???)))

我应该写什么而不是写???

我试图使用向量内部的数组,但是我没有这样成功。

先感谢您

i want to store a vector of objects for a node and subset of set.
so I want to implement a 3 d vector where the first dimension has size #nodes = n and the second dimension has size 2^|set| = m. the last dimension shouldn't have fixed size, because I want to append new objects in my program.

vector< vector < vector<Object>>> Vector3d( n , ( m, ( ( ???)))

what should I write instead of ???

i have tried to use arrays inside of a vector, but I didn't succeed that way.

thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是一片海 2025-02-11 07:42:08

初始化的方法是

vector< vector < vector<Object>>> Vector3d(n,vector<vector<Object>(m))

这将有效,因为它将初始化第一个维度的大小为n,其中包含n no vector&lt; vector&vector&lt; object&gt;(m)哪个是默认值。现在,第二维的大小定义为M,没有初始值,因此您可以将任何向量附加到第二维空间。

ie

vector<Object> v;
Vector3d[i][j].push_back(v);

i和j是前两个维度的索引

The method of initialisation is

vector< vector < vector<Object>>> Vector3d(n,vector<vector<Object>(m))

This will work, as it will initialize the first dimension's size as n, which would contain n no of vector<vector<Object>(m) which is the default value. Now the size of the second dimension is defined as m, which has no initial value, hence you can append any vector to the second dimension space.

i.e.

vector<Object> v;
Vector3d[i][j].push_back(v);

where i and j are the indexes of the first 2 dimensions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文