const and volatile are called cv-qualifier by the C spec.
What is exactly defference between specifier and qualifier (cv-qualifier)? Is a qualifier is a specifier as well?
Is it necessarry that qualifier is with an lvalue only?
What are qualifiers other than cv-qualifier?
Does my above understanding make any sense?
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
constqualifier that you show in your example withfoois just a syntactic form, which actually means that the const-qualifier is applied to the impliedthisparameter of thefoomethod:const A* this. I.e. in this case it does indeed qualify an lvalue, but it is*this, notfoo.The term qualifier also appears in the context of qualified names. Name like
some_class::some_member(orsome_namespace::some_name) are called qualified names and thesome_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 = 5is an lvalue, yet you can’t modify it. Ordinary functions are also lvalues in C++, yet you can’t modify a function.