Re: [問題] 關於 lecture#4 的更正

看板EE_DSnP作者 (Ric)時間17年前 (2006/11/18 17:11), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
※ 引述《EEmuse2 (忘了密碼)》之銘言: : 標題: Re: [問題] 關於 lecture#4 的更正 : 時間: Sat Nov 18 16:50:33 2006 : : ※ 引述《samuelduan ()》之銘言: : : map<string, int> scores; : : pair<map<string, int>::iterator, bool> p : : = scores.insert(make_pair(“John”, 100)); : ~~~~~~~~~~~~~~~~~~~~~ : : 上面的是更正的版本 : : 而我之前查了一些資料 : : 有人寫成 : : map<string, int> scores; : : pair<map<string, int>::iterator, bool> p : : = scores.insert(pair(“John”, 100)); : : 或是 : : map<string, int> scores; : : pair<map<string, int>::iterator, bool> p : : = scores.insert(map<string, int>::value_type(“John”, 100)); : : 不知道上面幾種寫法有什麼不一樣呢? : : : 不好意思,想請問一下 : : 我研究了很久,還是不太會pair的用法,我只知道first,second分別代表 : : construct出來的物件,講義的這整句語法意思有點霧煞煞... : 你可以想成 --- template <class First, class Second> struct pair { First first; Second second; }; 既然它是 "struct", 表示你可以直接 access 它的 data members. So, given "pair<A, B> p(a, b)", p.first is equal to a, p.second is equal to b. : : : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 140.112.4.247 : → EEmuse2:另外想再問,CmdRegPair物件可以用在哪@@ 11/18 16:51 Please see post #155, my push. Used to construct a pair for map insertion. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.21.240
文章代碼(AID): #15NiujG0 (EE_DSnP)
討論串 (同標題文章)
文章代碼(AID): #15NiujG0 (EE_DSnP)