c++ - 如何将引用绑定(bind)到初始化程序

标签 c++

我一直在阅读C++ Primer这本书,我有一个问题:

  1. When we ask for a reference to an auto-deduced type, top-level consts in the initializer are not ignored.

  2. As usual, consts are not top-level when we bind a reference to an initializer.

在第一句中,我可以举个例子来理解:

const int ci = 0;
auto &g = ci;   // g is a reference of const int, bind to ci

我如何理解第二句话?如何将引用绑定(bind)到初始化程序?

最佳答案

使用 = 符号将引用绑定(bind)到初始化器(迂腐地说,一个对象被用作初始化器)。您发布了一个示例:

auto &g = ci;

初始化器 ci 绑定(bind)到引用 g

关于c++ - 如何将引用绑定(bind)到初始化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360191/

相关文章:

c++ - 理解 new[] 中的顺序

c++ - 如何运行一个cgi程序

c++ - PCL : PCLvisualizer multiple point clouds (XYZ) in same viewport with different colours

c++ - 如何在C++中扩展包含环境变量的路径

c++ - 如果使用全局函数,则 type_trait 的成员会失败

c++ - 安装 socket.io C++

c++ - boost::asio::serial_port 设置 RTS DTS

c++ - 自动将指向派生类的指针列表转换为指向基类的指针列表

C++ NaN 字节表示在赋值期间发生变化

C++ 编译错误非类类型