看板 C_and_CPP 關於我們 聯絡資訊
我現在程式碼是像這樣子 #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
tsaiminghan:vecotor不是本身就有排序的方法? 05/25 22:00
tsaiminghan:我對stl不熟,不知道這樣行不行? &ivector[i] 05/25 22:01
herman602:作業規定排序必須自己寫 不能使用stl內建的 05/25 22:05
herman602:所以才有這樣的需求 05/25 22:05
tsaiminghan:現在學校有教stl? 05/25 22:07
herman602:我希望可以一次傳入整個vector, 然後直接存取 05/25 22:08
herman602:但又不要用到額外空間, 所以想要採用call by reference 05/25 22:10
tsaiminghan:你要是傳入vector當參數嗎? 05/25 22:11
herman602:對@@ 05/25 22:11
tsaiminghan:aaa(vector<int> &vec) 這樣不知道對不對 05/25 22:13
tsaiminghan:傳參考的方式 05/25 22:14
herman602:無法將參數 1 從 'std::vector<_Ty> *' 轉換成 05/25 22:18
herman602:'std::vector<_Ty> &' 05/25 22:19
herman602:阿 呼叫的時候弄錯了 應該是 aaa(vec); 這樣 05/25 22:21
herman602:問題解決了 感謝:) 05/25 22:21
tsaiminghan:在function內用的時 ,直接用不用加* 05/25 22:21
tsaiminghan:解決了,那就沒事了 05/25 22:22