Correlation between specifier and qualifier?

前端 未结 2 1426
野的像风
野的像风 2020-12-30 05:38

const and volatile are called cv-qualifier by the C spec.

What is exactly defference between specifier and

2条回答
  •  隐瞒了意图╮
    2020-12-30 05:42

    Most of it doesn't make sense.

    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-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.

    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.

    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.

    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.

提交回复
热议问题