[問題] std::set 傳遞至function
DEVc++ 5.3.0.4
問題(Question):在傳遞std::set到function時,如何call by reference
餵入的資料(Input):在main function 初始化一set,之後call其他function
insert 數字
預期的正確結果(Expected Output):在main function得到已經insert數字的
set
錯誤結果(Wrong Output):main function 的set甚麼都沒有
程式碼如下
#include <iostream> // std::cout
#include <set>
using namespace std;
void f(set<int> myset){
set<int>::iterator it;
for(int i=1;i<11;i++){
myset.insert(i*10);
}
}
int main ()
{
set<int> myset;
set<int>::iterator it;
f(myset);
for(it=myset.begin();it!=myset.end();it++){
cout<<*it<<" ";
}
cout<<endl;
return 0;
}
小弟初次接觸set
感謝各位大大囉
※ 編輯: ijack 來自: 118.166.94.53 (10/14 23:49)
→
10/14 23:53, , 1F
10/14 23:53, 1F
→
10/15 00:19, , 2F
10/15 00:19, 2F
→
10/15 00:20, , 3F
10/15 00:20, 3F
→
10/15 00:26, , 4F
10/15 00:26, 4F
→
10/15 00:26, , 5F
10/15 00:26, 5F
→
10/15 02:22, , 6F
10/15 02:22, 6F
→
10/17 13:37, , 7F
10/17 13:37, 7F