在类中初始化boost :: multi_array [英] initialize boost::multi_array in a class

查看:124
本文介绍了在类中初始化boost :: multi_array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说我是新手.

For start I would like to say that I am newbie.

我正在尝试在班级内部初始化boost:multi_array.我知道如何创建boost:multi_array:

I am trying to initialized boost:multi_array inside my class. I know how to create a boost:multi_array:

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

但是作为课程的一部分,我遇到了问题:

but as part of a class I have problems:

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])中指控一个元素时,我得到了一个错误.

My program passes through compilation but during run-time I get an error when I try to accuse an element from foo (e.g. foo[0]).

如何解决这个问题?

推荐答案

使用初始化列表(顺便说一句,我知道有关Boost的这部分的邮政编码,因此请按照您的代码进行操作):

Use an initialisation list (BTW, I know zip about this bit of Boost, so I'm going by your code):

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

这篇关于在类中初始化boost :: multi_array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆