const 限定转换
从 (4.4/1 ) 读取
“指向 cv1 T 的指针”类型的右值可以转换为 如果“cv2 T”比“cv1 T”更符合 cv 条件,则键入“pointer to cv2 T”。
我不知道标准在哪里定义了“更多 cv 限定字段”类型,但据我了解,const 声明符比非 const 声明符更符合 cv 限定条件。
对于以下转换,标准中的引用如何适应,或者您如何知道哪一个更符合简历要求?
int *const c1 = 0;
int const* c2 = 0;
const int *const c3 = 0;
c1 = c2; // allowed
c1 = c3; // allowed
更新:
c2 = c1;
c2 = c3;
From (4.4/1 ) It reads
An rvalue of type “pointer to cv1 T” can be converted to an rvalue of
type “pointer to cv2 T” if “cv2 T” is more cv-qualified than “cv1 T.”
I don't know where the standard defines 'more cv-qualifield' type but as I understood a declarator with const is more cv-qualified than than a non-const.
For following conversions, how does the quote from standard fits in or how you know which one is less or more cv-qualifed?
int *const c1 = 0;
int const* c2 = 0;
const int *const c3 = 0;
c1 = c2; // allowed
c1 = c3; // allowed
Update:
c2 = c1;
c2 = c3;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
3.9.3/4 中的表 6 给出了 cv 限定符的部分排序,3.9.3/4 还给出了更多 cv 限定符的定义。
const
易失性
const 易失性
const
const 易失性
易失性
常量易失性
Table 6 in 3.9.3/4 gives the partial ordering of cv-qualifiers and 3.9.3/4 also gives the definition of more cv-qualified.
const
volatile
const volatile
const
<const volatile
volatile
<const volatile
由于
c1
是一个const
指针变量(与指向常量数据的指针不同),因此无法对其进行修改。因此,这两项分配都是非法的。该标准指的是这种情况:
Since
c1
is aconst
pointer variable (which is different to a pointer to constant data), it cannot be modified. Therefore, both assignments are illegal.What the standard refers to is this case:
它是§3.9.3/4
也就是说,
const T
比T
更符合 cv 条件。易失性 T
比T
更符合简历要求。const volatile T
比T
更符合 cv 条件。const volatile T
比const T
更符合 cv 条件。const volatile T
比volatile T
更符合 cv 条件。It is §3.9.3/4
That is,
const T
is more cv-qualified thanT
.volatile T
is more cv-qualified thanT
.const volatile T
is more cv-qualified thanT
.const volatile T
is more cv-qualified thanconst T
.const volatile T
is more cv-qualified thanvolatile T
.