C++ 常量引用,用来修饰形参,防止误操作
void func(const int &b){ b=1000;// cout << b << endl; } int main(){ int a =10; //const int &b = 10; //10是一个常量 int a =10 实际是 const int &b = 10; int &b = a; func(a); return 0; }
void func(const int &b){ b=1000;// cout << b << endl; } int main(){ int a =10; //const int &b = 10; //10是一个常量 int a =10 实际是 const int &b = 10; int &b = a; func(a); return 0; }