3D 向量构造函数 C++
对于 2d 矢量,我知道我可以:
vector<vector<T>> vec;
vec = vector<vector<T>> (boardSize, vector<T>(boardSize));
但是对于 3d 矢量我该如何做呢?
我尝试过
vector<vector<vector<T>>> vec;
vec = vector<vector<vector<T>>> (boardSize, boardSize, vector<T>(boardSize));
但它无法编译。有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是猜测:
这意味着,当您声明了
vector>
时,第二个参数应该是vector
;当您声明vector>>
时,第二个参数应该是vector>
,反过来应该和第一种情况一样。Just a guess:
That means, when you've declared a
vector<vector<T>>
, the second argument should be avector<T>
; and when you declared avector<vector<vector<T>>>
, the second argument should be avector<vector<T>>
, which in turn should be as in the first case.也许最好的办法就是不这样做。创建一个提供 3D 矢量接口的类(使用 一些更改)并在内部使用单维向量。
Probably the best thing would be not to do it. Create a class that offers the interface of a 3D vector (with some changes) and internally use a single dimension vector.