在浏览 SO 上另一个问题的答复时遇到了这个(引用与变量获取 https://stackoverflow.com/questions/3744635/c-is-it-a-good-idea-to-always-return-references-for-member-variable-getters)。
我的问题是,对于所有 64 位环境,是否能保证对变量的引用为 64 位,即使原始变量的大小较小?就像 64 位环境中的 char 引用会是 >sizeof(char)?标准中是否有任何章节明确规定了这一点?
编辑:为了更清楚——
字符 c1 = 'a';
字符& c2 = c1;
我的问题是 64 位机器中的 sizeof(c2) > sizeof(c1) ?
标准 (ISO C++-03) 对于引用有以下规定
It is unspecified whether or not a reference requires storage (3.7).
如果我错了或者我没有正确理解他的问题,请有人纠正我。
EDIT:
我的问题是 64 位机器中的 sizeof(c2) > sizeof(c1) ?
No, as @Chubsdad https://stackoverflow.com/users/418110/chubsdad注意到sizeof(c2) = sizeof (c1)
,标准中的相关引用是
When applied to a reference or a reference type, the result is the size of the referenced type
。 (ISO C++ $5.3.3/2)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)