vector作为参数的三种传参方式
c++中常用的vector容器作为参数时,有三种传参方式,分别如下
- function1(std::vector<std::vector<int> > vec),传值
- function2(std::vector<std::vector<int> >& vec),传引用
- function3(std::vector<std::vector<int> >* vec),传指针
三种方式对应的调用形式分别为:
- function1(vec),传入值
- function2(vec),传入引用
- function3(&vec),传入地址