头文件
#include<vector>
如vector <int> a; 即声明一个int型a[],大小没有固定,可动态增加
vector作为参数的三种传参方式:
c++中常用的vector容器作为参数时,有三种传参方式,分别如下(为说明问题,用二维vector):
- function1(std::vector<std::vector<int> > vec),传值
- function2(std::vector<std::vector<int> >& vec),传引用
- function3(std::vector<std::vector<int> >* vec),传指针
注意,三种方式分别有对应的const形式,不在此讨论。
三种方式对应的调用形式分别为:
- function1(vec),传入值
- function2(vec),传入引用
- function3(&vec),传入地址
三种方式的效果分别为:
- 会发生拷贝构造
- 不会发生拷贝构造
- 不会发生拷贝构造