[問題] class、template用法請教[改了點問題]

看板C_and_CPP (C/C++)作者 (angelaa)時間14年前 (2012/03/17 03:46), 編輯推噓0(004)
留言4則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC2010 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) PCL (Point Cloud Library) 問題(Question): template < typename PointInT, typename PointNT, typename PointOuT> class XXX{ public: XXX(); void compute(); private: pcl::PointCloud< PointInT > cloud; <<<<<<<<<<<<<<問題點 ... }; 問題是這樣的: pcl::PointCloud< XX > 是一個類似 vector的東西 提供了一個指標的用法 pcl::PointCloud< XX >::Ptr 我希望可以用  pcl::PointCloud< PointInT >::Ptr 這樣使用他 在compute()裡面 像一般使用一樣的去讀到裡面的值 ex: pcl::PointCloud< PointInT >::Ptr cloud; cloud.point[i].x 這樣取得內容值 可是失敗了.. 我試過在 public加 typedef pcl::PointCloud< PointInT > PointC; typedef typename PointC::Ptr PointCPtr; 但是我在function中仍然沒辦法使用Point裡面的成員 請問: 要加上甚麼 才能夠在class裡面 順利使用這些東西呢? 我有看過該library其他的.h檔 但是 看了好久 悟不出甚麼東西來 麻煩各位幫幫忙~感激不敬 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.65.203

03/17 12:46, , 1F
看不太懂你的問題,可否給完整一點的code和錯誤訊息?
03/17 12:46, 1F
我用vector來說明好了~ vector< int >::const_iterator 這是vector裡面其中一個function 假設我在class裡面想這樣用 template< typename T> class XXX{ public: vector< int >::const_iterator intiter <<<<可以過也可以用 vector< T >::const_iterator Titer <<這邊就沒辦法用vector的function }; 我的問題則是 要怎樣 才能讓vector< T >::下面的functoin使用? ※ 編輯: abc01251 來自: 118.160.66.99 (03/17 15:22)

03/17 15:49, , 2F
宣告dependent type的前面要加"typename"
03/17 15:49, 2F
我加過 typedef typename vector< T >::const_iterator NType; NType Titer; 但是還是不能用下面的function耶~ ※ 編輯: abc01251 來自: 118.160.66.99 (03/17 16:56)

03/17 22:31, , 3F
http://ideone.com/0OkLH 像這樣? 其實我還是不懂你的
03/17 22:31, 3F

03/17 22:32, , 4F
問題是什麼
03/17 22:32, 4F
文章代碼(AID): #1FOvYY4k (C_and_CPP)
文章代碼(AID): #1FOvYY4k (C_and_CPP)