[問題] 指標用法 vector<自定義結構>

看板C_and_CPP作者 (與未來共舞)時間11年前 (2015/01/16 13:02), 11年前編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC2010 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我想將vector<LBP_Encoder> 型態用指標方式傳入函數, 目的是 [為了傳入函數並修改結構內資料], 但指標與向量&結構概念結合不太清楚, 想知道如何宣告比較能達成 餵入的資料(Input): vector<LBP_Encoder> encoder 預期的正確結果(Expected Output): encoder.roi 內容成功修改 錯誤結果(Wrong Output): 無法執行 Error:no operator "<<" matches these operands 程式碼(Code):(請善用置底文網頁, 記得排版) struct LBP_Encoder{ DAB_Model model; Rect roi; int splitx; int splity; }; typedef struct LBP_Encoder LBP_Encoder; vector<LBP_Encoder> encoder; vector<LBP_Encoder> *ptr; ptr=&encoder; cout<< *ptr.roi.x <<endl; LDP_based_on_Landmark(ptr); 補充說明(Supplement): 我是弱弱的機械初學者QQ... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.199.217 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1421384569.A.8A5.html ※ 編輯: rilak1314 (140.118.199.217), 01/16/2015 13:03:40

01/16 13:59, , 1F
宣告 LDP_based_on_Landmark(vector<LBP_Encoder>&vec);
01/16 13:59, 1F

01/16 13:59, , 2F
call的時候直接LDP_based_on_Landmark(encoder); 就好
01/16 13:59, 2F

01/16 14:51, , 3F
謝謝大大!!
01/16 14:51, 3F

01/17 01:58, , 4F
cout<< (*ptr).roi.x <<endl;
01/17 01:58, 4F

01/17 01:58, , 5F
cout<< ptr->roi.x <<endl;
01/17 01:58, 5F
文章代碼(AID): #1Kk9jvYb (C_and_CPP)