看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《LikaiHo ( )》之銘言: : 想請問各位高手們.. : 今天有兩個vector容器,型別分別是int及double, : 我利用template的方式把iterator指向該二容器, : 程式碼如下,但是跑不過去.... : #include "stdafx.h" : #include <cstdlib> : #include <iostream> : #include <vector> : using namespace std; : template <class T> : void PrintOut(T& container) : { : if (container.empty()) ^^^^^^^^^^^^^^^^^ 既然你這樣用 表示 T 是 vector<int> 或 vector<double> : cout << "容器為空..."; : else : { : vector<T>::iterator ptr; //宣告指位器 所以把 T 代換進去 這樣就變成 vector< vector<int> >::iterator ptr 這應該不是你要的 : cout << "容器內資料為:"; : for(ptr=container.begin();ptr!=container.end();ptr++) : cout << *ptr << " "; : cout << "\n\n"; : } : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.15.163
LikaiHo:了解了.. 謝謝 :) 01/03 16:49