在the draft C++11 standard: N3337我找到了多个对 top-level cv-qualifiers
的引用,但没有定义。
最佳答案
来自 Dan Saks 的 Top-Level cv-Qualifiers in Function Parameters :
In C++, a cv-qualifier that applies to the first level of a type is called a toplevel cv-qualifier. For example, in:
T *const p;
the top-level cv-qualifier is
const
, and in:T const *volatile q;
the top-level cv-qualifier is
volatile
. On the other hand:T const volatile *q;
has no top-level cv-qualifiers. In this case, the cv-qualifiers
const
andvolatile
appear at the second level.The signature of a function includes all cv-qualifiers appearing in that function’s parameter types, except for those qualifiers appearing at the top-level of a parameter type.
For example, in:
int f(char const *p);
the
const
qualifier is not at the top level in the parameter declaration, so it is part of the function’s signature.On the other hand, in:
int f(char *const p);
the
const
qualifier is at the top level, so it is not part of the function’s signature. This function has the same signature as:int f(char *p);
我在标准中也找不到定义,但我在上面发布的内容在 N3337 §8.3.5-5 中有明确说明
After producing the list of parameter types, any top-level cv-qualifiers modifying a parameter type are deleted when forming the function type.
编辑: 在撰写上述帖子时,无法找到标准中的定义,但现在有一个 as pointed out by Shafik :
n4296 摘录:
In this International Standard, the notation cv (or cv1 , cv2 , etc.), used in the description of types, represents an arbitrary set of cv-qualifiers, i.e., one of {const}, {volatile}, {const, volatile}, or the empty set. For a type cv T, the top-level cv-qualifiers of that type are those denoted by cv. [Example: The type corresponding to the type-id const int& has no top-level cv-qualifiers. The type corresponding to the typeid volatile int * const has the top-level cv-qualifier const. For a class type C, the type corresponding to the type-id void (C::* volatile)(int) const has the top-level cv-qualifier volatile. — end example ]
关于c++ - C++11标准中 `top-level cv-qualifiers`的定义在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24676824/