在map迭代器中,(* iter).second anditer-> second之间有区别吗? [英] In map iterator is there a difference between (*iter).second anditer->second?
问题描述
我在代码中看到了很多前者,并且想知道是否有一个
的技术原因
I see that a lot of former in the code, and wonder if there is a
technical reason for that
推荐答案
" puzzlecracker" < ir ********* @ gmail.comwrote in message
news:81 ********************* ************* @ 56g2000h sm.googlegroups.com ...
"puzzlecracker" <ir*********@gmail.comwrote in message
news:81**********************************@56g2000h sm.googlegroups.com...
>我看到很多前者在代码,并想知道是否有一个
技术原因为
>I see that a lot of former in the code, and wonder if there is a
technical reason for that
你问的是语言语法,这是
并不特定于地图或迭代器。
给定指向类或结构的指针:
struct T >
{
int member;
};
和指向其中一个结构的指针:
T obj;
T * p(& obj);
两个表达式:
(* p)。会员
和
p->会员
具有完全相同的含义。
'' - >''形式是(*)的''速记''。形式。
为什么有人使用后者而不是前者我
我不知道。也许是一个风格问题,或者可能是代码生成器创造的问题。
-Mike
>
8月19日,9:48 * am,Mike Wahler < mkwah ... @ mkwahler.netwrote:
On Aug 19, 9:48*am, "Mike Wahler" <mkwah...@mkwahler.netwrote:
" puzzlecracker" < ironsel2 ... @ gmail.com写信息
新闻:81 *********************** *********** @ 56g2000h sm.googlegroups.com ...
"puzzlecracker" <ironsel2...@gmail.comwrote in message
news:81**********************************@56g2000h sm.googlegroups.com...
我在代码中看到很多前者,并且奇迹如果有
的技术原因那么b $ b
I see that a lot of former in the code, and wonder if there is a
technical reason for that
你问的是语言语法,这是
不是特定于地图或迭代器。
给定指向类或结构的指针:
struct T
{
* * int member;
};
和指向其中一个结构的指针:
T obj;
T * p(& obj);
两个表达式:
(* p).member
和
p->会员
具有完全相同的含义。
'' - >''形式是(*)的''速记''。形式。
为什么有人使用后者而不是前者我
我不知道。 *也许是''风格''问题,或者可能是代码生成器创建的
。
-Mike
You''re asking about language syntax, this is
not specific to map or iterators.
Given a pointer to a class or struct:
struct T
{
* * int member;
};
and a pointer to one of these structs:
T obj;
T *p(&obj);
The two expressions:
(*p).member
and
p->member
have exactly the same meaning.
The ''->'' form is ''shorthand'' for the (*). form.
Why someone used the latter over the former I
don''t know. *Perhaps a ''style'' issue, or possibly
that''s what a code generator created.
-Mike
我相信Mayers提到了关于地图或其他
容器的两个操作员的区别 - 我不记得了。
这不是风格问题。
I believe Mayers mentioned something in regard to map or another
container the difference of two operators -- I don''t recall it.
It''s NOT the matter of style.
19日前,11:06,puzzlecracker< ironsel2 ... @ gmail。 comwrote:
On 19 ago, 11:06, puzzlecracker <ironsel2...@gmail.comwrote:
8月19日,9:48 * am,Mike Wahler < mkwah ... @ mkwahler.netwrote:
On Aug 19, 9:48*am, "Mike Wahler" <mkwah...@mkwahler.netwrote:
" puzzlecracker" < ironsel2 ... @ gmail.comwrote in message
"puzzlecracker" <ironsel2...@gmail.comwrote in message
news:81 *************** ******************* @ 56g2000h sm.googlegroups.com ...
news:81**********************************@56g2000h sm.googlegroups.com...
>我在代码中看到很多前者,并想知道是否有一个
技术原因为
>I see that a lot of former in the code, and wonder if there is a
technical reason for that
你问的是语言语法,这不是特定于map或迭代器的
。
You''re asking about language syntax, this is
not specific to map or iterators.
给定指向类或结构的指针:
Given a pointer to a class or struct:
struct T $ / $
{
* * int member;
struct T
{
* * int member;
};
};
和指向其中一个结构的指针:
T obj;
T * p(&安培; OBJ);
and a pointer to one of these structs:
T obj;
T *p(&obj);
两个表达式:
The two expressions:
(* p).member
(*p).member
和
and
p-> member
p->member
具有完全相同的含义。
have exactly the same meaning.
'' - >''形式是(*)的''速记''。形成。
The ''->'' form is ''shorthand'' for the (*). form.
为什么有人使用后者而不是前者我
我不知道。 *也许是一个''style''问题,或者可能是'b $ b',这就是代码生成器所创造的。
Why someone used the latter over the former I
don''t know. *Perhaps a ''style'' issue, or possibly
that''s what a code generator created.
-Mike
-Mike
我相信Mayers提到了关于地图或其他的事情
容器两个操作员的区别 - 我不记得了。
这不是风格问题。
I believe Mayers mentioned something in regard to map or another
container the difference of two operators -- I don''t recall it.
It''s NOT the matter of style.
嗨。
两者之间没有区别。但是,以下
注释可以在SGI文档站点上看到STL:
"定义operator-for iterators取决于一个特性是部分
的C ++语言,但尚未实现所有C ++
编译器。如果您的编译器还不支持此功能,那么
解决方法是使用(* it).m而不是它 - > m。
这涉及一些过去的日子。今天大多数编译器确实提供了这样一个功能。因此,我同意Mike的观点,这可能是''风格''
问题。
-
Leandro TC Melo
Hi.
There''s no difference between the two of them. However, the following
note can be seen on the SGI documentation site for the STL:
"Defining operator-for iterators depends on a feature that is part
of the C++ language but that is not yet implemented by all C++
compilers. If your compiler does not yet support this feature, the
workaround is to use (*it).m instead of it->m."
This regards to some "old days". Today most compilers do provide such
a feature. Therefore, I agree with Mike that is probably a ''style''
issue.
--
Leandro T. C. Melo
这篇关于在map迭代器中,(* iter).second anditer-> second之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!