向量作为C ++中的数据成员 [英] vector as a Data Member in C++

查看:149
本文介绍了向量作为C ++中的数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,如何在我的类中包含101个元素向量作为数据成员?我正在做以下,但它似乎不工作:

In C++, how do I include a 101 elements vector as a data member in my class? I'm doing the following, but it doesn't seem to be working:

private:
    std::vector< bool > integers( 101 );

我已经包含了向量头。提前致谢!

I already included the vector header. Thanks in advance!

推荐答案

class myClass {
    std::vector<bool> integers;
public:
    myClass()
        : integers(101)
    {}
};



我也喜欢 std :: array 理念。如果你真的不需要这个容器在运行时改变它的大小,我建议使用固定大小数组选项

I also like the std::array idea. If you really don't need this container to change it's size at run-time, I will suggest going with the the fixed size array option

这篇关于向量作为C ++中的数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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