const引用和非const引用.txt
来自「里面的代码是自己写的,参考书是thingking in c++,代码有详细的说明」· 文本 代码 · 共 20 行
TXT
20 行
/*本程序选自thinking in c++ P453
* 本程序在于说明:Temporary objects are always const,so if you don't use
* a const reference instead of a nomal reference, that argument won't be
* accepted by the compiler.
*/
#include <iostream>
void f( int& ) {}
void g( const int & ){}
void mian()
{
//f(1); //error,临时变量不能传给非const引用。
g(1);
g(2.678);
float ff = 100.001;
//f(ff); //error C2664: “f” : 不能将参数 1 从“float”转换为“int &”
g( ff );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?