gpt4 book ai didi

c++ - Boost MultiArray 复制构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:58:15 25 4
gpt4 key购买 nike

我在理解 boost::multi_:array 的复制构造函数实现时遇到了问题。

当我尝试以下操作时

std::vector<double> a;
std::vector<double> b;
a.resize(12);
b.resize(10);
a=b;

一切顺利

但是当我尝试

boost::multi_array<double,1> a;
boost::multi_array<double,1> b;
a.resize(boost::extents[12]);
b.resize(boost::extents[10]);
a=b;

我崩溃了。

我预计会出现相同的行为,但我在文档中也找不到任何有用的信息。

有没有人有想法?

问候

墙拉布

最佳答案

在赋值方面,boost::multi_array 的工作方式与 std::valarray 类似,即两个数组的大小必须匹配。

根据 the documentation :

Each of the array types multi_array, multi_array_ref, subarray, and array_view can be assigned from any of the others, so long as their shapes match.

关于c++ - Boost MultiArray 复制构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6583354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com