作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] 关於 lecture#4 的更正
时间Sat Nov 18 17:16:35 2006
※ 引述《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