说明符和限定符之间的相关性? [英] Correlation between specifier and qualifier?
问题描述
const
和 volatile
被称为 cv-qualifier
说明符
和限定符之间的正义是什么c $ c>(
cv-qualifier
)?
是否必须有限定符
只有一个左值?
Is it necessarry that qualifier
is with an lvalue only?
除 cv-qualifier
之外的限定符是什么?
What are qualifiers other than cv-qualifier
?
推荐答案
大部分没有意义。
和限定符是在C ++标准中定义的。 例如,声明中的类型说明符可以包含 cv-qualifiers 。我没有看到为这个主题的标准引用一切的原因。
Specifier and qualifier are defined in the C++ standard. Qualifier is just an integral part of a specifier. For example, type specifier in a declaration can include cv-qualifiers. I don't see the reason to quote everything from the standard on this topic.
Cv限定符不限于lvalue。类类型的Rvalues也可以是cv限定。
Cv-qualifiers are not restricted to lvalues. Rvalues of class types can also be cv-qualified. It is possible to cv-qualify an rvalue of non-class type, but it will have no effect and will be ignored.
的使用可以通过cv-qualify非类型的右值来实现, const
限定符在你的示例中显示的 foo
只是一个句法形式,这实际上意味着const-qualifier应用于隐含
方法的
参数:
const A * this
。也就是说在这种情况下,它确实符合一个左值,但它是 * this
,而不是 foo
。
The use of const
qualifier that you show in your example with foo
is just a syntactic form, which actually means that the const-qualifier is applied to the implied this
parameter of the foo
method: const A* this
. I.e. in this case it does indeed qualify an lvalue, but it is *this
, not foo
.
术语限定词也出现在限定名的上下文中。像 some_class :: some_member
(或 some_namespace :: some_name
)的名称称为限定名称和 some_class ::
部分是限定符。
The term qualifier also appears in the context of qualified names. Name like some_class::some_member
(or some_namespace::some_name
) are called qualified names and the some_class::
part is a qualifier.
是一个左值,那么你可以修改它是完全不正确的。有可修改的左值和不可修改的左值。一个声明为 const int i = 5
的对象是一个左值,但你不能修改它。普通函数在C ++中也是左值,但你不能修改函数。
The idea that if something is an lvalue then you can modify it is totally incorrect. There are modifiable lvalues and non-modifiable lvalues. An object declared as const int i = 5
is an lvalue, yet you can't modify it. Ordinary functions are also lvalues in C++, yet you can't modify a function.
这篇关于说明符和限定符之间的相关性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!