I thought I d try beefing up my C++ and OpenGL by looking at the recently-released Doom 3 source. Much learned so far, but I ve hit a wall. The class detailed here has methods
float operator[] (int index) const
and
float & operator[] (int index)
两个机构改为
return ( &x )[ index ];
<代码>x为2类数据成员之一(另一个为y
;这一类别为2名查询人)。
虽然我可以理解每个版本的头盔/提纲,但我看不出他们为什么都在场。
const
seems to appear (or not appear, as preferred) only to distinguish the headers sufficiently to allow compilation. (That is, remove const
and VS2010 refuses to compile, similarly if both headers end in const
.)
And why return a ref to a float? None of the class seven other float-type methods do this, so I m guessing efficiency isn t a factor (tho maybe this operator s called vastly more often than the others).
Appreciate any insight as to what s going on here...