Re: [STL ] 請問List
看板C_and_CPP (C/C++)作者tyc5116 (累人啊....)時間16年前 (2009/07/14 21:11)推噓2(2推 0噓 8→)留言10則, 4人參與討論串4/10 (看更多)
: 推 Ebergies:就是你看到的意思 07/13 15:11
: → tyc5116:不懂... 07/13 15:22
: 推 Ebergies:把 n 換成 75, 就這樣... 07/13 15:28
: → iamivers0n:Non-type template parameter 07/13 15:30
: → tyc5116:不是很懂....我看我先研究個幾天好了....@@ 07/13 16:04
: → iamivers0n:就如同你所看到的 樣板參數是一個整數 07/13 18:24
: → Cloud:你可以先不管...就先照你認為的寫看看..之後就懂了..QQ 07/13 18:54
不好意思,複習了一下,我還是把我的一些問題提出來問問好了....@@
先列出這個網頁所提供的範例
template<int n>
class CComp{
public:
bool operator()(const C& lhs)
{
return (lhs.v2==n);
}
};
1.以他最後所寫出的find_if(cv.begin(),cv.end(),CComp<75>());來看
我有用到這一種operator嗎...??
以及像Cloud大所說的,配合我的結構,我把他改過了,先貼出我原本的架構
class TP_Gra{//TP.h
public:
TP_Gra(int vID,Point vOrigin_Position);
TP_Gra();
~TP_Gra();
void Set_ID(int vID){ID=vID;}
int Get_ID(){return ID;}
void Set_Coodinate(Point Position);
Point Get_Coodinate(){return Origin_Position;}
private:
int ID;
Point Origin_Position;
};
class Truckload_TP_Gra{//Truckload.h
typedef list<TP_Gra> Contents;
public:
Truckload_TP_Gra();
Truckload_TP_Gra(TP_Gra one_TP);
void add_TP(TP_Gra new_TP);
int Get_First_Ob_ID();
int Get_Last_Ob_ID();
Point Get_First_Ob_Coodinate();
Point Get_Last_Ob_Coodinate();
private:
Contents Load;
};
template<int n> class Find_Ob_by_ID{//fun.h
public:
bool operator()(TP_Gra& lhs)
{
return (lhs.v2==n);
}
};
然後我在主程式那寫了這樣的程式碼
list<TP_Gra>::iterator cviter=
find_if(Token_Place.Get_First_Ob_ID(),
Token_Place.Get_Last_Ob_ID(),
Find_Ob_by_ID<pb->Name>());
(上面全部打成同一行)
然後出現了這樣的錯誤訊息
error C2975: 'n' : 對 'Find_Ob_by_ID' 無效的樣板引數,必須是編譯時期常數運算式
error C2440: '正在初始化' : 無法由 'int' 轉換為
'std::list<_Ty>::_Iterator<_Secure_validation>'
請問....我該怎麼解決呢?謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.18.48.28
推
07/14 21:16, , 1F
07/14 21:16, 1F
→
07/14 21:17, , 2F
07/14 21:17, 2F
→
07/14 21:17, , 3F
07/14 21:17, 3F
→
07/14 21:18, , 4F
07/14 21:18, 4F
推
07/14 21:18, , 5F
07/14 21:18, 5F
→
07/14 21:20, , 6F
07/14 21:20, 6F
→
07/14 21:20, , 7F
07/14 21:20, 7F
→
07/14 21:22, , 8F
07/14 21:22, 8F
→
07/14 21:47, , 9F
07/14 21:47, 9F
→
07/14 21:49, , 10F
07/14 21:49, 10F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章