Re: [問題] 關於 lecture#4 的更正
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 5 篇):