作者herman602 (奸商)
看板C_and_CPP
标题[问题] 关於STL的vector
时间Mon May 25 21:54:14 2009
我现在程式码是像这样子
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> ivector;
for(int i = 0; i < 10; i++)
{
ivector.push_back(i);
}
return0;
}
我要如何把ivector用call by reference传给另一个排序的副程式?
感谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.195.38.221
1F:→ tsaiminghan:vecotor不是本身就有排序的方法? 05/25 22:00
2F:→ tsaiminghan:我对stl不熟,不知道这样行不行? &ivector[i] 05/25 22:01
3F:→ herman602:作业规定排序必须自己写 不能使用stl内建的 05/25 22:05
4F:→ herman602:所以才有这样的需求 05/25 22:05
5F:推 tsaiminghan:现在学校有教stl? 05/25 22:07
6F:→ herman602:我希望可以一次传入整个vector, 然後直接存取 05/25 22:08
7F:→ herman602:但又不要用到额外空间, 所以想要采用call by reference 05/25 22:10
8F:推 tsaiminghan:你要是传入vector当参数吗? 05/25 22:11
9F:→ herman602:对@@ 05/25 22:11
10F:→ tsaiminghan:aaa(vector<int> &vec) 这样不知道对不对 05/25 22:13
11F:→ tsaiminghan:传参考的方式 05/25 22:14
12F:→ herman602:无法将参数 1 从 'std::vector<_Ty> *' 转换成 05/25 22:18
13F:→ herman602:'std::vector<_Ty> &' 05/25 22:19
14F:→ herman602:阿 呼叫的时候弄错了 应该是 aaa(vec); 这样 05/25 22:21
15F:→ herman602:问题解决了 感谢:) 05/25 22:21
16F:→ tsaiminghan:在function内用的时 ,直接用不用加* 05/25 22:21
17F:→ tsaiminghan:解决了,那就没事了 05/25 22:22