gpt4 book ai didi

c++ - 在类中初始化 boost::multi_array

转载 作者:可可西里 更新时间:2023-11-01 18:27:44 26 4
gpt4 key购买 nike

首先我想说我是新手。

我正在尝试初始化 boost:multi_array在我的类(class)里。我知道如何创建 boost:multi_array :

boost::multi_array<int,1> foo ( boost::extents[1000] );

但作为类(class)的一部分,我遇到了问题:

class Influx {
public:
Influx ( uint32_t num_elements );
boost::multi_array<int,1> foo;

private:

};

Influx::Influx ( uint32_t num_elements ) {
foo = boost::multi_array<int,1> ( boost::extents[ num_elements ] );
}

我的程序通过了编译,但在运行时,当我尝试从 foo 中调用一个元素时出现错误(例如 foo[0] )。

如何解决这个问题?

最佳答案

使用初始化列表(顺便说一句,我知道关于这部分 Boost 的 zip,所以我按照你的代码进行):

Influx::Influx ( uint32_t num_elements ) 
: foo( boost::extents[ num_elements ] ) {
}

关于c++ - 在类中初始化 boost::multi_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2053106/

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