矢量作为类成员 [英] Vector as a class member

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

问题描述

Hello我有这个问题:
我想有一个向量作为类成员。这可能是我的问题
对你来说更容易,我为此道歉。

Hello I have this question: I would like to have a vector as class member. This is perhaps my question easier for you and I apologize for that.


  • 如何声明向量?这是正确的吗? std :: vector< int> * myVector; std :: vector< int> myVector

  • 如何在dealloc中处理此向量?

  • 如何将数组初始化为if?

  • how should I declare the vector? And is this correct? std::vector<int> *myVector; or std::vector<int> myVector ?
  • how should I handle this vector in dealloc?
  • How can I initialize the array into a if?

这是否正确?

if(myCondition)
{
   if(!myVector) //is this correct?
       myVector = new std::vector<int>(); //is this correct? on this i have a error
}


推荐答案

你最肯定想使用 std :: vector< int> myVector 。无需初始化它,因为它会自动在您的类的构造函数中初始化,并在您的类被销毁时释放。

You most certainly want to use std::vector<int> myVector. No need to initialize it, as it gets automatically initialized in the constructor of your class and deallocated when your class is destroyed.

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

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