【问题标题】:in c++ how to declare 3D dimensional vector in a 3D dimensional vector [closed]在 C++ 中如何在 3D 维向量中声明 3D 维向量 [关闭]
【发布时间】:2016-08-22 17:24:30
【问题描述】:

如何在 C++ 中声明一个 3D 维度向量,以便每个元素依次是一个 3d 向量,其大小我之前会考虑。

【问题讨论】:

  • 为什么不std::vector
  • “一个 3D 向量,其中每个元素又是一个 3D 向量”——那么你想要一个 9D 向量吗?
  • @ArchbishopOfBanterbury 这将是一个 6D 向量

标签: c++ boost stl


【解决方案1】:

如果您使用的是 C++11:

template <typename T>
using three_d_vector = std::vector<std::vector<std::vector<T>>>;
template <typename T>
using six_d_vector = std::vector<std::vector<std::vector<three_d_vector<T>>>>;
template <typename T>
using nine_d_vector = std::vector<std::vector<std::vector<six_d_vector<T>>>>;

然后你会像nine_d_vector&lt;int&gt; 一样使用它,或者你正在使用的任何类型。请注意,这与嵌套std:vector 九次完全相同。老实说,特别是如果您使用各种其他维度进行此操作,您可能只想使用 n 维度向量,如 here 所示。

【讨论】:

  • 哎呀,这是一个很好的观点。已编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-24
  • 2013-08-03
相关资源
最近更新 更多