Re: [STL ] list 的使用問題
看板C_and_CPP (C/C++)作者LPH66 ((short)(-15074))時間16年前 (2009/08/21 23:59)推噓1(1推 0噓 0→)留言1則, 1人參與討論串2/2 (看更多)
※ 引述《yhn0tgb60 (呦厚厚)》之銘言:
: 我宣告一個
: list < float[3] > path;
: float pos[3];
: 在程式中 pos[3] 中會有很多筆資料要存入 path 中
: 我用 path.push_front(pos); 將pos[3]放入 path的最前面
: 可是complie 過不了 系統回傳的錯誤很複雜看不懂
: 請問要怎麼處裡這問題
: 還有 如果我程式要 return(path);
: 那個 return 的 type是什麼??? float* ? list ? list<float[3]>?
: 麻煩大家了 謝謝
: 推 su31o4gj83:list <float *> path; 08/21 21:45
: → su31o4gj83:type : list <float *> 08/21 21:48
: → yhn0tgb60:太感恩了 過了 謝謝 08/21 21:51
過了歸過了 這是你要的嗎?
(看起來完全不像...因為這樣的話會存進讀進資料的位置
如果你的 pos 會重覆使用的話必會出錯)
我的建議是建個 struct 裡面就只含那三個 float
(例如 struct coord {float x,y,z;}; )
然後宣告 list<coord> path; 這樣就行了
---
那個回傳 直接 return path; 的 cost 是很兇的...
(因為會把整個 list<coord> 連同裡面的所有東西複製一份出來)
你要不要反過來把函式寫成用 pass by reference 把一個 list<coord> 丟進去
裡面再對它去改 這樣的 cost 會比較少...
--
'You've sort of made up for it tonight,' said Harry. 'Getting the
sword. Finishing the Horcrux. Saving my life.'
'That makes me sound a lot cooler then I was,' Ron mumbled.
'Stuff like that always sounds cooler then it really was,' said
Harry. 'I've been trying to tell you that for years.'
-- Harry Potter and the Deathly Hollows, P.308
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.30.84
※ 編輯: LPH66 來自: 140.112.30.84 (08/22 00:03)
推
08/22 02:34, , 1F
08/22 02:34, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章