为什么参考简历的格式不正确?
Why cv-qualification for a reference is ill-formed?
根据dcl.ref/1:
符合 Cv 标准的引用格式不正确,除非 cv 限定符 通过使用 typedef-name 引入
所以我试过:
int a = 1;
int& const r1 = a;
并得到错误:
error: 'const' qualifiers cannot be applied to 'int&'
预计会提示诊断消息。
但是,我想知道为什么禁止它。
只是为了防止程序员实际表示时编写上述代码的意外
:const int& r1 = a; // const reference to int
主要问题
2(或者是否有一些更深层次的原因/实际例子,为什么不允许它确实是有益的?
有什么想法吗?
CV 限定符对指针有效:
int a;
int * const p = &a;
这适用于指针本身,而不是它指向的内容。
但是,由于您无法在定义后更改引用,因此将 CV-Q 添加到引用中是没有意义的。
相关文章:
- 非静态成员函数的 decltype 格式不正确吗?
- HTTP 响应格式不正确?
- 实例化具有不完整类型的类模板格式不正确(如果该类型是在之后定义的)
- 注意:"Entity_c::Entity_c(const Entity_c&)"被隐式删除,因为默认定义格式不正确:
- C++ std::vector 中的外部类(定义格式不正确)
- 输出使用 cout 转换为 ASCII 的文本时输出格式不正确,C++
- 为什么参考简历的格式不正确?
- 被隐式删除,因为默认定义格式不正确:
- 为什么 (int&)0 格式不正确?
- 下面的代码是格式不正确的 NDR 还是格式正确的代码
- 尝试访问类的私有成员以消除重载是否格式不正确
- 使用派生自 'std::tuple' 的元素在 'std::tuple' 上调用 'std::get' - 格式不正确
- 尝试使用 boost::asio 连接到 SOCKS 5 服务器,但我的连接请求格式不正确
- “在成员函数之外封闭类的定义中需要默认成员初始值设定项” - 我的代码格式不正确
- 为什么以下模板声明格式不正确
- C++构造函数被隐式删除,因为默认定义的格式不正确
- 错误:隐式删除,因为默认定义格式不正确(结构向量)
- 提升日志时间戳格式不正确
- 在 C++11 标准中哪里说 char* p = "abc" ;格式不正确?
- 在重载解析中,选择使用不明确转换序列的函数是否必然会导致调用格式不正确