- 论坛徽章:
- 0
|
各位, 请教一下, 在<C++程序设计语言>(特别版)一书中的5.5节有一段话:
References to variables and references to constants are distingished because the introduction of a temporary in the case of the variable is highly error-prone; an assignment to the variable would become an assignment to the - soon to disappear - temporary. No such problem exists for references to constants, and references to constants are often important as function argument.
文中提到, 对变量和对常量的引用是不相同的, 因为对变量的引用会引进临时变量.
但是在书中的代码如下:
- const double &cdr = 1;
- 其实为
- double temp = double(1);
- const double &cdr = temp;
复制代码
在这里, 是对一个常量的引用时引进的临时变量.
不知道是我哪儿理解错了, 谢谢各位指教! |
|